【終結版】sql 按照周 月 季度 年進行彙總
阿新 • • 發佈:2019-02-12
--按日
--按周quarter
--按月 ]) ='2006'
--按季
selectsum(consume),day([date]) from consume_record whereyear([date]) ='2006'
groupbyday([date])
--按周quarter
selectsum(consume),datename(week,[date]) from consume_record whereyear([date]) ='2006'
groupbydatename(week,[date])
--按月
selectsum(consume),month([date]) from consume_record whereyear([date
groupbymonth([date])
--按季
selectsum(consume),datename(quarter,[date]) from consume_record whereyear([date]) ='2006'
groupbydatename(quarter,[date])
--指定日期你就看上面的例子變通下呀,無非就是一個聚合函式和Group by
select[date],sum(consume) from consume_record where[date]
between'2006-06-01'and'2006-07-10'groupby[date]