SQL grouping sum

Source: Internet
Author: User

Requirement: there are multiple release regions in a month, and now the monthly release quota is required. For example, the monthly release quota -- 35900, and the monthly release quota -- 2300

The SQL statement is as follows:

-- Grouping by month, Sum

Select dmonth, codename, sum (iamount) from

(

-- Obtain all the dates and release the release token.
Select convert (varchar (7), a. dregdate, 120) as dmonth, A. coper_code + '-' + W. work_name as codename
, Iamount as iamount
From viw_executeall
Inner join tbl_worksub s on Left (A. coper_code, 2) = S. work_group
Inner join tbl_dealer D on A. ccorp_code = D. cdealer_code
Inner join tbl_work w on W. work_code = A. coper_code
Where a. iamount> 0 and S. cmemo = 1 and Bbig = 0 and (dfrom_date <= '2017-07-30 ') and
(Dto_date> = '1970-06-01 ') and S. ccity_name = 'beijing' and D. cyyzzcode = '1'
) AA

Group by dmonth, codename

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.