SELECT f1,(SELECT SUM(f1) AS total
FROM test AS b
WHERE (id < a.id)) AS Expr1
FROM test AS a
------其他解决方案-------------------- 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 ------其他解决方案--------------------
WHERE (id <=a.id) ------其他解决方案-------------------- 貌似这个要用到递归 ------其他解决方案--------------------