mysql中将查询结果按照时间进行分组和统计
按照分钟进行统计:
DATE_FORMAT(create_time, '%Y-%m-%d %H:%i')
按照小时进行统计:
DATE_FORMAT(create_time, '%Y-%m-%d %H')
按照天数进行统计:
DATE_FORMAT(create_time, '%Y-%m-%d')
按照月份进行统计:
DATE_FORMAT(create_time, '%Y-%m-%d')
按照分钟进行统计:DATE_FORMAT(create_time, '%Y-%m-%d %H:%i') 按照小时进行统计:DATE_FORMAT(create_time, '%Y-%m-%d %H') 按照天数进行统计:DATE_FORMAT(create_time, '%Y-%m-%d') 按照月份进行统计:DATE_FORMAT(create_time, '%Y-%m-%d')
SELECT
DATE_FORMAT(create_time, '%Y-%m') createTimeByMin, source,count(1) AS orderCount
FROM xxx.tablename where biz_code='555'
AND create_time < '2020-11-07' AND create_time BETWEEN '2020-11-06 13:00:00' AND '2020-11-06 18:31:59'
GROUP BY createTimeByMin,source;
------------------------- A little Progress a day makes you a big success... ----------------------------