--> liangCK小梁 于2008-08-06 --> 生成测试数据: @T declare @T table (no int,val int) insert into @T select 1,19 union all select 2,37 union all select 3,43 union all select 4,98select no,val, val2=(select sum(val) from @t where no<=t.no) from @T t/* no val val2 ----------- ----------- ----------- 1 19 19 2 37 56 3 43 99 4 98 197(4 行受影响) */
--> 生成测试数据: @T
declare @T table (no int,val int)
insert into @T
select 1,19 union all
select 2,37 union all
select 3,43 union all
select 4,98select no,val,
val2=(select sum(val) from @t where no<=t.no)
from @T t/*
no val val2
----------- ----------- -----------
1 19 19
2 37 56
3 43 99
4 98 197(4 行受影响)
*/
如上