select coll,value,(select sum(value) from 表 where col1<=a.col1) sum1
from 表 a

解决方案 »

  1.   

    能不能用update 写出来。详细些
      

  2.   

    declare @sum1 int
    set @sum1=0
    update 表 set @sum1=@sum1+value,sum1=@sum1
      

  3.   

    或者
    update 表 set sum1=(select sum(value) from 表 a where a.col1<=表.col1)
      

  4.   

    是不是这样:
    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我不是很清楚你的意思
      

  5.   

    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 行)
      

  6.   

    update 表 set sum1=b.sum1 from (select coll,(select sum(value) from 表 where coll<a.coll) sum1 from 表 a) b where 表.coll=b.coll
    是不是这样笨了点