Use SQL statements by week, month, quarter, yearly

Source: Internet
Author: User

--according to MySQL grammar statistics by week, month, quarter, year. Income is the total Price field and CreateDate is the trading time. Select sum(income) asRevenue,week (CreateDate) asWeekMonth(CreateDate) as Month, Quarter (CreateDate) asQuarter Year(CreateDate) as  Year  fromEmployeewhere  Year(CreateDate)>= '2006' Group  byWeek (createdate),Month(CreateDate), Quarter (CreateDate), Year(createdate)--sqlserver2005 Grammar statistics by week, month, quarter, year. --by day--Select SUM (Price), day ([date]) from table_name where year ([date]) ='2006' Group  by  Day([Date])--by week quarterSelect sum(Price),Datename(Week,price_time) fromBle_namewhere Year(Price_time)= ' -' Group  by Datename(week,price_time)--by MonthSelect sum(Price),Month(Price_time) fromBle_namewhere  Year(price_time)= ' -' Group  by Month(price_time)--by seasonSelect sum(Price),Datename(Quarter,price_time) fromBle_namewhere Year(Price_time)= ' -' Group  by Datename(quarter,price_time)--by yearSelect sum(Price), Year(Price_time) fromBle_namewhere Year(Price_time)>= ' -' Group  by  Year(Price_time)

Use SQL statements by week, month, quarter, yearly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.