mysql自定义时间段分组

时间:2023-03-09 18:31:20
mysql自定义时间段分组

说明:一下是自定义7天为一个时间段的分组统计

select datediff(ms_time, '开始时间') div 7 as time , count(*) count,sum(money) money
from merchant_statistics
WHERE ms_time BETWEEN '2019-02-02' and '2019-03-02'
group by (datediff(ms_time, '开始时间') div 7)