首页 > 技术文章 > mysql自定义时间段分组

Superb1995 2019-04-23 14:31 原文

说明:一下是自定义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)

推荐阅读