数据库 DB 数据:
warning_info 是对应的DB表,create_date 是字段
SELECT time30, COUNT(*) AS num
FROM (select DATE_FORMAT(time, '%Y-%m-%d %H:%i') as time30
from (SELECT DATE_FORMAT(
concat(date(create_date), ' ', HOUR(create_date), ':', floor(MINUTE(create_date) / 30) * 30),
'%Y-%m-%d %H:%i') AS time
FROM warning_info) a) as b
GROUP BY time30
order by time30;
结果:time30 表示从这个时刻往前30分钟。第一条数据即:5:00 ~5:30 分
转载自:https://www.cnblogs.com/wjx-blog/p/10119575.html