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
*/