读书人

求1SQL语句 求指导

发布时间: 2012-10-26 10:30:59 作者: rapoo

求一SQL语句 求指导
我有两张表
A表
countsbg_type
31
13
24

B表
countsbg_type
11
12
13

求如下结果
countsbg_type
41
12
23
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楼的吧

读书人网 >SQL Server

热点推荐