Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping data by a time stamp

Status
Not open for further replies.

txwylde

Programmer
Jan 25, 2001
60
0
0
US
I have a query where I am doing some counts as data is coming in. There is a order_time field where I am selecting hour(order_time) as hr and then grouping by the data and HR. If I wanted to break the order_time in 15 minute increaments, how would I got about doing that?

Thanks!
Bill
 
Code:
SELECT DATE_FORMAT(order_time,CONCAT('%Y-%H','-',CEILING(MINUTE(order_time)/15)*15)) as my15min,count(*) FROM SOME_TABLE GROUP by my15min;
 
on closer examination the following is more accurate, as minutes that divide exactly into 15 are allocated properly

Code:
SELECT DATE_FORMAT(order_time,CONCAT('%Y-%H','-',(FLOOR(MINUTE(order_time)/15)+1)*15)) as my15min,count(*) FROM SOME_TABLE GROUP by my15min;
 
Here is the order_time field:

02:00:59
HH:MM:SS

I tried
DATE_FORMAT(order_time,CONCAT('%Y-%H','-',(FLOOR(MINUTE(order_time)/15)+1)*15)) as my15min

but it does not group it in 15 min increaments. Is there something I am doing wrong?
Thanks!
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top