select id , [sum]=(select sum(b) from ta where id!>a.id) from ta a
declare @ta table(ID int, B decimal(15,2)) insert @ta select 1, 2.1 union all select 2, 1.2 union all select 3, 3.5select id, [sum]=(select sum(b)from @ta where id!>a.id) from @ta a(3 行受影响) id sum ----------- --------------------------------------- 1 2.10 2 3.30 3 6.80(3 行受影响)
from ta a
insert @ta select 1, 2.1
union all select 2, 1.2
union all select 3, 3.5select id,
[sum]=(select sum(b)from @ta where id!>a.id)
from @ta a(3 行受影响)
id sum
----------- ---------------------------------------
1 2.10
2 3.30
3 6.80(3 行受影响)