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
李小家