34,837
社区成员




with tt as (
select *,ROW_NUMBER()over(partition by Region order by Name) rn
from t
)
select *,(select SUM(sku) from tt t2 where t2.Region=tt.Region and t2.rn<=tt.rn ) 累加列--sku如果是字符串,需要转型
from tt
with tb as
(
select *,row_number()over(order by getdate())rn from table1 --table1你的表
)
select a.*,b.累加列from tb a cross apply (select Name,SUM(SKU)as [累加列] from tb where rn<=a.rn group by Name) b where a.Name=b.Name