declare @t table (进出数量 int)
insert into @t
select 10 union all
select -20 union all
select 30 union all
select -10
;with m as
(select row_number() over (order by (select 1)) as rid,进出数量 from @t)
select 进出数量,累计数量=
(select sum(进出数量) from m where rid<=a.rid) from m a
/*
进出数量 累计数量
----------- -----------
10 10
-20 -10
30 20
-10 10
*/
------解决方案-------------------- 真厉害