Possible Duplicate:
Group records by time
I have a mysql table that logs web page requests.
I'd like to write a sql that outputs the number of requets per hour.
INPUT:
timestamp browser
------------------- -------
2012-06-28 15:06:14 chrome
2012-06-28 15:12:15 IE6
2012-06-28 16:32:16 IE7
OUTPUT:
timestamp count
------------------- -------
2012-06-28 15:00:00 2
2012-06-28 16:00:00 1
I'm guessing my first step would be to 'truncate' the datetime field so that I can do a group-by. Searching, I have found some examples of rounding the hour, but none to truncate.
select count(no_of_requests) from table group by date(datetime_field) , hour(datetime_field)
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