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