I have a Table with a "Date" Column. I want to group by hour for a specific date.
When you want to group by minute, hour, day, week, etc., you may be tempted to just group by your timestamp column. The datepart() function has the same syntax as the datename() function. Therefore, both functions can be used in the same way.
We can use the group by multiple column technique to group multiple records into a single record. All the records that have the same values for the respective columns mentioned in the grouping criteria can be grouped as a single column using the group by multiple column technique.
You can also do this:
SELECT TRUNC(datecol, 'HH24') FROM mytable GROUP BY TRUNC(datecol, 'HH24');
Select TO_CHAR(date,'HH24') from table where date = TO_DATE('20110224', 'YYYYMMDD') group by TO_CHAR(date,'HH24')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With