declare @sum1 int set @sum1=0 update 表 set @sum1=@sum1+value,sum1=@sum1
或者 update 表 set sum1=(select sum(value) from 表 a where a.col1<=表.col1)
是不是这样: declare @coll int declare ##ls cursor for select coll from table open ##ls fetch next from ##ls into @coll while @@tetch_status=0 begin update table set sum1=(select sum(value) from table where coll<=@coll) where coll=@coll fetch next from ##ls into @coll end close ##lzy_ls deallocate ##lzy_ls我不是很清楚你的意思
create table tb(col int,value int,sum1 int) insert tb values(1,10,0) insert tb values(2,15,0) insert tb values(3,50,0) select a.col,a.value,sum1=(select sum(value) from tb where col<=a.col) from tb a col value sum1 ----------- ----------- ----------- 1 10 10 2 15 25 3 50 75(所影响的行数为 3 行)
update 表 set sum1=b.sum1 from (select coll,(select sum(value) from 表 where coll<a.coll) sum1 from 表 a) b where 表.coll=b.coll 是不是这样笨了点
set @sum1=0
update 表 set @sum1=@sum1+value,sum1=@sum1
update 表 set sum1=(select sum(value) from 表 a where a.col1<=表.col1)
declare @coll int
declare ##ls cursor for select coll from table
open ##ls
fetch next from ##ls into @coll
while @@tetch_status=0
begin
update table set sum1=(select sum(value) from table where coll<=@coll) where coll=@coll
fetch next from ##ls into @coll
end
close ##lzy_ls
deallocate ##lzy_ls我不是很清楚你的意思
insert tb values(1,10,0)
insert tb values(2,15,0)
insert tb values(3,50,0) select a.col,a.value,sum1=(select sum(value) from tb where col<=a.col)
from tb a
col value sum1
----------- ----------- -----------
1 10 10
2 15 25
3 50 75(所影响的行数为 3 行)
是不是这样笨了点