wldrumstcs
09-24-2010, 02:42 PM
I have a PostgreSQL table with multiple columns including "oper_time" of type "timestamp without time zone". I wanted to output the time as well as the count(*) and group the data by hour and by every 15 minutes. In other words, I want to the output to look like:
hr | mn | thecount
---------------------------
11 | 00 | 38
11 | 15 | 52
11 | 30 | 79
11 | 45 | 51
12 | 00 | 54
12 | 15 | 33
etc....
Here's what I have so far, but it tells me I need to group by oper_time or use it in an aggregate function. However, I don't want to group by oper_time, and I'm not sure where to go from here.
SELECT extract(hour from oper_time) as hr, extract(minute from oper_time) as mn,count(*) as thecount
FROM log WHERE CAST(oper_time As Date) >= '09/23/2010'
GROUP BY CAST(oper_time as Date),extract(hour from oper_time),floor(extract(minute from oper_time)/15)
ORDER BY CAST(oper_time as Date),extract(hour from oper_time),extract(minute from oper_time)
Thanks!
hr | mn | thecount
---------------------------
11 | 00 | 38
11 | 15 | 52
11 | 30 | 79
11 | 45 | 51
12 | 00 | 54
12 | 15 | 33
etc....
Here's what I have so far, but it tells me I need to group by oper_time or use it in an aggregate function. However, I don't want to group by oper_time, and I'm not sure where to go from here.
SELECT extract(hour from oper_time) as hr, extract(minute from oper_time) as mn,count(*) as thecount
FROM log WHERE CAST(oper_time As Date) >= '09/23/2010'
GROUP BY CAST(oper_time as Date),extract(hour from oper_time),floor(extract(minute from oper_time)/15)
ORDER BY CAST(oper_time as Date),extract(hour from oper_time),extract(minute from oper_time)
Thanks!