表1:
ID   值
1    5
2    4
3    7
4    8返回:
ID   值
1    5
2    9
3    16
4    24

解决方案 »

  1.   

    累加,楼主自己改一下
    ====================
    create table test
    (c1 int,
    c2 char(1))insert test (c1,c2)
    select 2,'a' union all
    select 4,'b' union all
    select 5,'c' union all
    select 9,'d' select * from test
    select (select sum(c1) from test where c1<=a.c1) as c1,c2 from test adrop table test
      

  2.   

    update tb1 a set 值=(select sum(值) from tb b where b.id<=a.id)
      

  3.   

    update tb1 a set 值=(select sum(值) from tb b where b.id<=a.id)
    ---------------------
    这个直接提示语法错误:
    Incorrect syntax near 'a'
      

  4.   

    打忘了,不好意思,update老是写select的语法update tb1 set 值=(select sum(值) from tb b where b.id<=id)
      

  5.   

    或者
    update a set 值=(select sum(值) from tb b where b.id<=a.id) from tb1 a
    都是随便打的,可能有手误,你试一下.
      

  6.   

    create table(
     id int not null identity(1,1),
     num int
    )insert aa values(5)
    insert aa values(4)
    insert aa values(7)
    insert aa values(8)
    update aa  set aa.num=(select sum(num) from aa b where b.id<=aa.id)这个一定行。不行的话,砍死我。
      

  7.   

    细看了一下这个没有问题.
    update a set 值=(select sum(值) from tb b where b.id<=a.id) from tb1 a
    另一个这样写.
    update tb1 set 值=(select sum(值) from tb where id<=tb1.id)