such as:
table: consume_record
Field:consume (money type)
date (datetime type)
How to write four SQL statements by day, weekly, monthly, quarterly statistics consumption totals.
such as: January 1200
February 3400 Yuan
March 2800 yuan &NBSP
- by day,
Select sum (consume), days ([date]) from consume_record where year ([date]) = ' 2006 ' group by day ([date])
--by week quarter
Select sum (Consume), Datename (Week,[date]) from consume_record where year ([date]) = ' 2006 ' group by datename (Week,[date])
-monthly
Select sum ( Consume), month ([date]) from consume_record where year ([date]) = ' 2006 ' Group by month ([date])
-Quarterly
Select sum (Consume), Datename (Quarter,[date]) from consume_record where year ([date]) = ' 2006 ' group by Datename (Quarter,[date])
-By year
Select sum (Consume), year ([date]) from Consume_record Group by year ([date])
--Specify a date you just look at the example above and work it out, it's just an aggregate function and GROUP by
Select [Date],sum (consume) from Consume_record where [date] between ' 2006-06-01 ' and ' 2006-07-10 ' group by [date]
SQL statements by day, by week, by month, by quarterly statistic amount