select 单位,[2002年总收入],[2003年总收入],[2003年比2002年增减(+,-)]=[2003年总收入]-[2002年总收入] from
(select 单位,sum(case year(日期) when 2002 then 收入1+收入2 else 0 end) '2002年总收入',
sum(case year(日期) when 2003 then 收入1+收入2 else 0 end) '2003年总收入' from A group by 单位) tem

解决方案 »

  1.   

    select 单位,sum(case when year(日期) = 2002 then 收入1+收入2 else 0 end) as [2002年总收入],sum(case when year(日期) = 2003 then 收入1+收入2 else 0 end) as [2003年总收入],sum(case year(日期) when 2003 then 收入1+收入2 when 2003 -收入1-收入2 end) as [2003年比2002年增减(+,-)]
    from 表 group by 单位
      

  2.   

    select 单位,sum(case year(日期) when 2002 then 收入1+收入2 else 0 end) [2002年总收入], sum(case year(日期) when 2003 then 收入1+收入2 else 0 end) [2003年总收入],sum(case year(日期) when 2003 then 收入1+收入2 else -(收入1+收入2) end ) [2003年比2002年增减(+,-)] from 表a group by 单位
      

  3.   

    to txlicenhe(马可)
    提示:end附近语法错误
      

  4.   

    sum(case year(日期) when 2003 then 收入1+收入2 else 0 end)
    sum(case year(日期) when 2003 then 收入1+收入2 else -(收入1+收入2) end )
    请问:这两句什么意思?
    如果第一句换成:sum(case year(日期) when 2003 then 收入1+收入2 else -(收入1+收入2) end )
    和原来有什么不同?谢谢