MySQL将数据按周聚合(自定义周的起始日)

$week_start = 0   // 0- 6: 周日-周六
SELECT: 

week_start=0:
CONCAT_WS('~', subdate(Fdate,date_format(Fdate,'%w')-$week_start), subdate(Fdate,date_format(Fdate,'%w')-$week_end) )
week_start=1-6:
CONCAT_WS('~', subdate(Fdate, if(date_format(Fdate, '%w')<$week_start,date_format(Fdate, '%w')+7-$week_start,date_format(Fdate,'%w')-$week_start)),
	subdate(Fdate, if(date_format(Fdate, '%w')<$week_start,date_format(Fdate,'%w')+7-$week_end,date_format(Fdate,'%w')-$week_end )) )
 
  


GROUP BY:

yearweek(Fdate, $week_start)


你可能感兴趣的:(DataBase)