Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql - how to count number of records in an hour (datetime) using sql [duplicate]

Tags:

sql

mysql

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.

like image 913
Eric Avatar asked Dec 13 '22 00:12

Eric


1 Answers

select count(no_of_requests) from table group by date(datetime_field) , hour(datetime_field)
like image 53
Muhammad Raheel Avatar answered Dec 28 '22 22:12

Muhammad Raheel