declare @i numeric(28,6),@j numeric(28,6),@V numeric(28,6)
set @i=0,@j=0
select *,0 as ValueCol into #temp from 表
update #temp 
    set ValueCol=((字段b+@j)-(字段a+@i))/(字段b+@j)
        ,@I=@i字段a
        ,@j=@j字段b
select * from #temp

解决方案 »

  1.   

    更正一下,
    declare @i numeric(28,6),@j numeric(28,6)
    set @i=0
    set @j=0
    select *,case(0 as numeric(28,6)) as ValueCol into #temp from 表
    update #temp 
        set ValueCol=((字段b+@j)-(字段a+@i))/(字段b+@j)
            ,@I=@i字段a
            ,@j=@j字段b
    select * from #temp
      

  2.   

    select identity(int,1,1) id,* from 你的表select ((select sum(b) from 你的表 where id<=tem.id)-(select sum(a) from 你的表 where id<=tem.id))/(select sum(b) from 你的表 where id<=tem.id) 结果 from 表
      

  3.   

    select identity(int,1,1) id,* from 你的表select ((select sum(b) from 你的表 where id<=tem.id)-(select sum(a) from 你的表 where id<=tem.id))/(select sum(b) from 你的表 where id<=tem.id) 结果 from 你的表 tem
      

  4.   

    DBMS:通过临时表或游标可实现~
    PB:利用datawindow实现起来更简单方便~
      

  5.   


    select *,cast(0 as decimal(10,2)) as v into #r from a
    declare @i decimal(10,4), @j decimal(10,4)  
    select @i=0,@j=0update #r
    set @i=@i+a,@j=@j+b,v=(@j-@i)/ @j
      

  6.   

    create proc addab1 
     as
     declare @aa int,@bb int 
     declare @sumab int,@addb int
     declare @diva real
     set @sumab=0
     set @addb=0
     declare a cursor for select a,b from addab
     
    open a
    fetch next from a into @aa,@bb
    while @@fetch_status=0
    begin
    set @sumab=@sumab+@aa
    set @addb=@addb+@bb
    set @diva=(@addb-@sumab)/@addb
    fetch next from a into @aa,@bb
    end close a
    deallocate a
      

  7.   

    select *, identity(int,1,1) as id into #t from yourtableselect a, b, (select (sum(a) - sum(b)) / sum(b) from #t where id <= A.id) result from #t as A
      

  8.   

    select *, identity(int,1,1) as id into #t from yourtableselect a, b, (select (sum(cast(a as numeric(8,4)) - sum(cast(b as numeric(8,4))) / sum(cast(b as numeric(8,4)) from #t where id <= A.id) result from #t as A
      

  9.   

    select *, identity(int,1,1) as id into #t from addabselect a, b, (select (sum(cast(b as float)) - sum(cast(a as float))) / sum(cast(b as float)) from #t where id <= A.id) result from #t as A