select id,num=(select sum(num) from tb where id<=t.id) from tb t
SELECT A.col1,col2 = (select sum(col2) from tb B where B.col1<=A.col1) from tb A
create table tb(id int,num int) insert into tb select 1,3 insert into tb select 2,8 insert into tb select 3,6select id,num=(select sum(num) from tb where id<=t.id) from tb tid num 1 3 2 11 3 17
select id,num=(select sum(num) from tb where id<=t.id) from tb t
if object_id('Plus') is not null drop table Plus create table Plus ( id int, PlusName int ) insert into Plus select 1,3 insert into Plus select 2,8 insert into Plus select 3,6select id,PlusName=(select sum(PlusName) from Plus where id<=P.id) from Plus P
declare @temp table ( a int , b int ) insert into @temp select 1,3 union all select 2,8 union all select 3,6 select a, b=(select sum(b) from @temp j where j.a<=c.a ) from @temp c
from tb t
insert into tb select 1,3
insert into tb select 2,8
insert into tb select 3,6select id,num=(select sum(num)
from tb where id<=t.id) from tb tid num
1 3
2 11
3 17
create table Plus
(
id int,
PlusName int
)
insert into Plus select 1,3
insert into Plus select 2,8
insert into Plus select 3,6select id,PlusName=(select sum(PlusName) from Plus where id<=P.id) from Plus P
declare @temp table
( a int ,
b int
)
insert into @temp select 1,3
union all select 2,8
union all select 3,6 select a, b=(select sum(b) from @temp j where j.a<=c.a ) from @temp c