| |

VerySource

 Forgot password?
 Register
Search
View: 643|Reply: 5

Masters don't want to laugh at me, or sincerely ask!

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-5 18:10:01
| Show all posts |Read mode
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
Reply

Use magic Report

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-6 19:33:01
| Show all posts
like
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-8 22:45:01
| Show all posts
select b.zyname company name, sum (total amount) from (select company id, company name, sum (amount) as total amount from
(
  select * from 1
  union all
  select * from 2
) t where approval opinion = 'agree'
group by company id, company name order by company id) a,
3 b
group by b.zyname
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-10 14:36:01
| Show all posts
Sweat wrong
select b.zyname company name, sum (total amount) from (select company id, company name, sum (amount) as total amount from
(
  select * from 1
  union all
  select * from 2
) t where approval opinion = 'agree'
group by company id, company name order by company id) a,
3 b
where b.gsname = a. company name
group by b.zyname
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-10 14:45:01
| Show all posts
Sweat wrong
select b.zyname company name, sum (total amount) from (select company id, company name, sum (amount) as total amount from
(
  select * from 1
  union all
  select * from 2
) t where approval opinion = 'agree'
group by company id, company name order by company id) a,
3 b
where b.gsname = a. company name
group by b.zyname
Reply

Use magic Report

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-16 15:36:01
| Show all posts
Go home and understand it carefully. I did n’t understand it too much. I implemented it and there were some problems.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list