Mysql跨年按周汇总


先定义一个比较日期,如果周开始为周日,那么这天必须为周日,如‘2014-03-23’


select date_add('2014-03-23',interval datediff(date,'2014-03-23') div 7*7 day) as week_start,  
date_add('2014-03-23',interval datediff(date,'2014-03-23') div 7*7+6 day)as week_end,sum(qty)
from table
group by datediff(date,'2014-03-23') div 7; 


你可能感兴趣的:(mysql)