My database is MySQL the Time field type is timestamp
This database inserts a record every once in a while, similar to the following:
id | datetime | data01 | data021 | 2015-06-10 00:00:00 | 23.8 | 33.72 | 2015-06-10 00:01:11 | 21.8 | 12.73 | 2015-06-10 00:01:30 | 21.8 | 33.74 | 2015-06-10 01:02:00 | 23.8 | 33.75 | 2015-06-10 01:03:10 | 23.8 | 33.7......209 | 2015-06-10 23:03:00 | 23.8 | 33.7
I now want to divide 24 hours statistics, such as the sum of all the data of 00:00:00-01:00:00, and so on, there is can only control the time, do not put the month and day also counted in, as long as the time interval,
Thank you all!
Reply content:
My database is MySQL the Time field type is timestamp
This database inserts a record every once in a while, similar to the following:
id | datetime | data01 | data021 | 2015-06-10 00:00:00 | 23.8 | 33.72 | 2015-06-10 00:01:11 | 21.8 | 12.73 | 2015-06-10 00:01:30 | 21.8 | 33.74 | 2015-06-10 01:02:00 | 23.8 | 33.75 | 2015-06-10 01:03:10 | 23.8 | 33.7......209 | 2015-06-10 23:03:00 | 23.8 | 33.7
I now want to divide 24 hours statistics, such as the sum of all the data of 00:00:00-01:00:00, and so on, there is can only control the time, do not put the month and day also counted in, as long as the time interval,
Thank you all!
sql
select count (*) from tablename where datetime between '2015-06-10 00:00:00' and '2015-06-10 01:00:00';
It's simple.
sql
select substring(`datetime`,12,2) as `hour`,count(*) as `total` from `table` group by `hour`;