按照季度统计
SELECT CONCAT(DATE_FORMAT(create_time, '%Y'),'-',FLOOR((DATE_FORMAT(create_time, '%m')+2)/3),'季度') AS QUARTER ,
COUNT(1) AS 总量 FROM 表 WHERE
create_time>'2021-01-01' AND create_time<'2022-01-01'
GROUP BY QUARTER
ORDER BY QUARTER;
按月统计
SELECT DATE_FORMAT(create_time,'%Y-%m') months,COUNT(1) COUNT
FROM 表
WHERE create_time>'2021-01-01' AND create_time<'2021-06-01'
GROUP BY months
ORDER BY months;
按周统计
SELECT DATE_FORMAT(create_time,'%Y%u') weeks,COUNT(1)COUNT FROM t_product_spu
WHERE create_time>'2021-01-01' AND create_time<'2021-03-26'
GROUP BY weeks
ORDER BY weeks;
按照天统计
SELECT DATE(create_time) AS DATE,COUNT(*) FROM 表
WHERE create_time<'2021-01-10'
GROUP BY DATE
ORDER BY DATE;
按照小时统计
SELECT DATE_FORMAT(create_time,'%Y-%m-%d %H:00:00') AS TIME,COUNT(*) FROM 表
WHERE create_time>'2021-03-25' AND create_time<'2021-03-26'
GROUP BY TIME
ORDER BY TIME;
标签:COUNT,01,FORMAT,create,mysql,分组,time,DATE,排序 From: https://www.cnblogs.com/mimeng/p/17109145.html