create table a(col1 int)
insert into a
select 100 union all
select 200 union all
select 300 select * from a
/*
col1
------
100
200
300
*/select col1,(select sum(col1) from a where col1<=i.col1) as col2 from a i/*
col1 col2
----------------
100 100
200 300
300 600
*/
drop table a
insert into a
select 100 union all
select 200 union all
select 300 select * from a
/*
col1
------
100
200
300
*/select col1,(select sum(col1) from a where col1<=i.col1) as col2 from a i/*
col1 col2
----------------
100 100
200 300
300 600
*/
drop table a
insert into a
select 100 union all
select 200 union all
select 300 select * from a
/*
col1
------
100
200
300
*/select col1,(select sum(col1) from a where col1<=i.col1) as col2 from a i/*
col1 col2
----------------
100 100
200 300
300 600
*/
drop table a
(select sum(col1) from a where id<=i.id) as col2 --ID序号
from a i