首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求1SQL语句 求指导

2012-10-26 
求一SQL语句求指导我有两张表A表countsbg_type311324B表countsbg_type111213求如下结果countsbg_type41122

求一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楼的吧

热点排行