没有看懂 ,年的合计小于累计合计,

解决方案 »

  1.   

    用游标,把当前的累计合计减去去年的累计合计就可以得本年合计
      

  2.   

    --e.g.
    create table #test(年份 int,累计合计 int)
    insert #test 
    select 2001,10000
    union select 2002,18000
    union select 2003,23000select * from #test
    select 年份,累计合计,累计合计-isNull((select 累计合计 from #test where 年份=a.年份-1),0) 本年合计 from #test a
    drop table #test
      

  3.   

    年份          累计合计        
    ----------- ----------- 
    2001        10000
    2002        18000
    2003        23000(所影响的行数为 3 行)年份          累计合计        本年合计        
    ----------- ----------- ----------- 
    2001        10000       10000
    2002        18000       8000
    2003        23000       5000(所影响的行数为 3 行)