日期:2014-05-17  浏览次数:20437 次

求一SQL语句 求指导
我有两张表
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_type
from 
(select * from a union all
 select * from b) K
group by bg_type

------解决方案--------------------
晕,猜了半天,用2楼的吧