34,590
社区成员
发帖
与我相关
我的任务
分享
select 编号,完成数=(select sum(完成数) from ta where 编号<=a.编号) from ta a
declare @tb table(编号 int, 完成数 int)
insert @tb select 1, 8
insert @tb select 2 , 8
insert @tb select 3 , 4
insert @tb select 4 , 7
insert @tb select 5 , 3
insert @tb select 6 , 3
declare @count int
set @count=0
update @tb set @count=@count+完成数,完成数=@count
select * from @tb
/*
编号 完成数
----------- -----------
1 8
2 16
3 20
4 27
5 30
6 33
(所影响的行数为 6 行)
*/
select
编号,
完成数=(select sum(完成数) from ta b where b.编号<=a.编号)
from ta a
Select 编号,sum(完成数) from tb a where not exists(select 1 from tb where 编号<=a.编号)
select 编号,完成数=(select sum(完成数) from tb where 编号<=a.编号) from tb a