SQL group by frequency within a date range

后端 未结 4 1935
攒了一身酷
攒了一身酷 2020-12-31 16:44

I have a requirement to write a stored procedure that accepts a start date, end date and a frequency (day, week, month, quarter, year) and outputs a result set based on thos

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 17:27

    select `date` as weekOf, sum(amt)
    from myTable
    where `date` between '2011-10-01' and '2012-01-01'
    group by week(`date` )
    

提交回复
热议问题