mysql按30分钟进行分组

SELECT time30, COUNT(*) AS num 
FROM
(
    select DATE_FORMAT(time,'%Y-%m-%d %H:%i') as time30
    from(
            SELECT DATE_FORMAT(concat(date(CALL_DATE), ' ',HOUR (CALL_DATE),':',floor(MINUTE(CALL_DATE)/30)*30),'%Y-%m-%d %H:%i' ) AS time FROM call_detail_records
        ) a 
) as b
GROUP BY time30;

 

posted @ 2018-12-14 15:15  星星c#  阅读(1029)  评论(0编辑  收藏  举报