declare @t1 table(id int, j1 int)
insert @t1
select 1, 20
union all select 2, 30
union all select 3, 40declare @t2 table(id int, j2 int)
insert @t2
select 1, 5
union all select 2, 6
union all select 2, 7
union all select 2, 8
union all select 3, 10
union all select 3, 15select a.id,a.j1,(select sum(j2) from @t2 where id = a.id ) as j2
from @t1 as a/*结果
id j1 j2
------------------------
1 20 5
2 30 21
3 40 25
*/
insert @t1
select 1, 20
union all select 2, 30
union all select 3, 40declare @t2 table(id int, j2 int)
insert @t2
select 1, 5
union all select 2, 6
union all select 2, 7
union all select 2, 8
union all select 3, 10
union all select 3, 15select a.id,a.j1,(select sum(j2) from @t2 where id = a.id ) as j2
from @t1 as a/*结果
id j1 j2
------------------------
1 20 5
2 30 21
3 40 25
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货