当前位置: 代码迷 >> Sql Server >> 求1SQL语句 求指导
  详细解决方案

求1SQL语句 求指导

热度:52   发布时间:2016-04-25 01:20:44.0
求一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_typefrom (select * from a union all select * from b) Kgroup by bg_type
------解决方案--------------------
晕,猜了半天,用2楼的吧
  相关解决方案