Query after merging multiple database tables (joint query)-union

1. There are several tables with exactly the same structure. I want to summarize these tables by a certain field.

Reference blog: http://blog.csdn.net/vinson0526/article/details/9367469
such as table upc1:

application count
http 3
ftp 4
www 10

Table upc2 :

application count
http 7
ftp 6
www 13

Finally, I want to get the following table tt:

application count
http 10
ftp 10
www 23

Code:

select application, sum(count) from (
select * from upc1 
union all
select * from upc2) tt 
group by applicaton;

Summary: union and union all can be used to merge tables with the same structure.

Guess you like

Origin blog.csdn.net/lx1848/article/details/77619832