SELECT HOUR(e.time)as Hour,FLOOR(MINUTE(e.time)/30) as M, COUNT(*) as Count
FROM error_log e
WHERE e.date = '2017-09-02'
GROUP BY FLOOR(MINUTE(e.time)/30),HOUR(e.time)
ORDER BY Hour(e.time);
floor函数是mysql 的向下取整函数 如 floor(1.2) = 1
以下是运行结果:
要查看每小时统计,请看这里 Mysql 查询一天中,每个小时数据的数量