sql语句分别按日,按周,按月,按季统计金额

表:consume_record

字段:consume (money类型)

date (datetime类型)

请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量.

如:1月 1200元

2月 3400元

3月 2800元

--按日

selectsum(consume),day([date])fromconsume_recordwhereyear([date])='2006'groupbyday([date])

--按周quarter

selectsum(consume),datename(week,[date])fromconsume_recordwhereyear([date])='2006'groupbydatename(week,[date])

--按月

selectsum(consume),month([date])fromconsume_recordwhereyear([date])='2006'groupbymonth([date])

--按季

selectsum(consume),datename(quarter,[date])fromconsume_recordwhereyear([date])='2006'groupbydatename(quarter,[date])

当然,如果你的oracle报错:'month'函数报错,可以试试 to_char(b.PAYMENT_TIME,'yyyy-mm')

你可能感兴趣的:(sql语句分别按日,按周,按月,按季统计金额)