首页 > mysql时间段统计问题

mysql时间段统计问题

我的数据库是mysql的 时间字段类型是Timestamp
这个数据库每隔一段时间就会插入一条记录,类似下面的:

id  |       datetime       |  data01  |  data02
1   | 2015-06-10 00:00:00  |   23.8   |   33.7
2   | 2015-06-10 00:01:11  |   21.8   |   12.7
3   | 2015-06-10 00:01:30  |   21.8   |   33.7
4   | 2015-06-10 01:02:00  |   23.8   |   33.7
5   | 2015-06-10 01:03:10  |   23.8   |   33.7
......
209 | 2015-06-10 23:03:00  |   23.8   |   33.7

我现在想分24小时统计,比如00:00:00-01:00:00的所有数据的总和,以此类推,还有就是能不能只控制时间,不要把年月日也算进去,只要时间区间,
感谢各位!


很简单啊

sqlselect substring(`datetime`,12,2) as `hour`,count(*) as `total` from `table` group by `hour`;

sqlselect count (*) from tablename where datetime between '2015-06-10 00:00:00' and '2015-06-10 01:00:00';
【热门文章】
【热门文章】