请试试select nsrsbh,sbrq,sum(ysse),sum(ysxssr) from table group by nsrsbh,year(sbrq)

解决方案 »

  1.   

    select nsrsbh as 纳税人识别号,
    sum(case year(sbrq) when 2003 then ysse else 0 end) as [2003年申报应税税额合计],
    sum(case year(sbrq) when 2003 then ysxssr else 0 end) as [2003年销售收入合计],
    sum(case year(sbrq) when 2004 then ysse else 0 end) as [2004年申报应税税额合计],
    sum(case year(sbrq) when 2004 then ysxssr else 0 end) as [2004年销售收入合计]
    from 一个表
    group by nsrsbh
      

  2.   

    select nsrsbh as 纳税人识别号,
    sum(case when left(sbrq,4)=2003 then ysse else 0 end) as [2003年申报应税税额合计],
    sum(case when left(sbrq,4)=2003 then ysxssr else 0 end) as [2003年销售收入合计],
    sum(case when left(sbrq,4)=2004 then ysse else 0 end) as [2004年申报应税税额合计],
    sum(case when left(sbrq,4)=2004 then ysxssr else 0 end) as [2004年销售收入合计]
    from 一个表
    group by nsrsbh
      

  3.   

    谢谢 P1mm(Plmm) ,你的方法完全正确!
    其余两位朋友也谢了,稍微给点分哈