|
Still the following statement:
select company id, company name, sum (amount) as total amount of money from
(
select * from 1
union all
select * from 2
) t where approval opinion = 'agree'
group by company id, company name order by company id
The purpose is to group the combined queries of Tables 1 and 2 into a summary, and now there is a new requirement as follows:
The result of executing the statement now may be as follows:
Company id Company name Total payment
1 Datong Branch 325
2 Chengde Branch 352
3 Yangquan Branch 158
4 Tangshan Branch 545
5 Shijiazhuang Branch 326
Now you need to add a table association. This table is a comparison table of company names, and the table name is 3.
The contents of his table may be as follows:
zyid zyname gsid gsname
1 Hebei Branch 2 Chengde Branch
2 Hebei Branch 4 Tangshan Branch
3 Hebei Branch 5 Shijiazhuang Branch
4 Shanxi Branch 1 Datong Branch
5 Shanxi Branch 3 Yangquan Branch
The need now is that the first summarized result should be associated with this company name comparison table to get a further summary.The summary result format is as follows:
Company name Total payment
Hebei Branch 1223
Shanxi Branch 483 |
|