sql 实现两个表的某列不相关的值相加,例如输入

输入:

输出:

应该有,等会,我测试一下,有思路了

--create table b1
--(
--a int,
--b int,
--c int
--)
--create table b2
--(
--a int ,
--b int ,
--d int
--)
--insert into b1
--select 1,1,2 union all
--select 3,2,1 union all
--select 4,2,2

--insert into b2
--select 2,1,1 union all
--select 4,2,2
go
select * from b1
go
select * from b2
select a,b,sum(c) as c from
(
select a ,b,c from b1
union all
select a,b,d as c from b2) aa
group by a,b
)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-05-01
做张临时表存放从两张表取出来的数据
然后做sum就可以了
相似回答