MySQL 按时间段统计SQL

按2小时段统计

select * from (SELECT FLOOR(HOUR(dateTimeColumn) / 2) * 2 as hour, count(id) as num FROM tableName group by hour ) tmp order by num

 

按1小时段统计

select * from (SELECT HOUR(dateTimeColumn) as hour, count(id) as num FROM tableName group by hour ) tmp order by num

 测试

posted @ 2023-11-24 19:52  李小加  阅读(110)  评论(0编辑  收藏  举报