declare @t table (进出数量 int)insert into @tselect 10 union allselect -20 union allselect 30 union allselect -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 -1030 20-10 10*/ ------解决方案-------------------- 真厉害