我也只是举个例子
tb是表名,id是字段
select id,(select sum(id) from (select id,rowindex=row_number()over(order by getdate()) from tb)source2
where source2.rowindex<=source1.rowindex)sumid from (select id,rowindex=row_number()over(order by getdate()) from tb) source1
with tb(id)
as(
select 2 union all
select 1 union all
select 4 union all
select 22
),
source as(
select id,rowindex=row_number()over(order by getdate()) from tb
)
select id,(select sum(id) from source source2 where source2.rowindex<=source1.rowindex)sumid from source source1