我有两张表
A表
counts bg_type
3 1
1 3
2 4
B表
counts bg_type
1 1
1 2
1 3
求如下结果
counts bg_type
4 1
1 2
2 3
2 4
------解决方案--------------------
select counts=sum(counts),bg_type
from (select * from A union all select * from B) t
group by bg_type
------解决方案--------------------
- SQL code
select counts=sum(counts),bg_typefrom (select * from a union all select * from b) Kgroup by bg_type
------解决方案--------------------
晕,猜了半天,用2楼的吧