/*
2007 10
2008 20
2009 30
2010 40
转换成
2007 10
2008 30
2009 60
2010 100
*/
declare @table table (col1 int,col2 int)
insert into @table
select 2007,10 union all
select 2008,20 union all
select 2009,30 union all
select 2010,40
select col1,col2,
col3=(select sum(col2) from @table where col1<=t.col1 and col2<=t.col2)
from @table t
/*
col1 col2 col3
2007 10 10
2008 20 30
2009 30 60
2010 40 100
*/
列的累加求和
最新推荐文章于 2024-09-24 00:51:03 发布