累加,楼主自己改一下 ==================== 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
update tb1 a set 值=(select sum(值) from tb b where b.id<=a.id)
update tb1 a set 值=(select sum(值) from tb b where b.id<=a.id) --------------------- 这个直接提示语法错误: Incorrect syntax near 'a'
打忘了,不好意思,update老是写select的语法update tb1 set 值=(select sum(值) from tb b where b.id<=id)
或者 update a set 值=(select sum(值) from tb b where b.id<=a.id) from tb1 a 都是随便打的,可能有手误,你试一下.
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)这个一定行。不行的话,砍死我。
细看了一下这个没有问题. 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)
====================
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
---------------------
这个直接提示语法错误:
Incorrect syntax near 'a'
update a set 值=(select sum(值) from tb b where b.id<=a.id) from tb1 a
都是随便打的,可能有手误,你试一下.
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)这个一定行。不行的话,砍死我。
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)