删选统计之后的数据如下
http://114.80.245.132:8088/images/bbb.jpg想要用SQL语句在过滤一下达到一下效果 求大神帮忙
http://114.80.245.132:8088/images/ccc.jpg

解决方案 »

  1.   

     select  name,一季度=isnull(sum(case quarter when 1 
     then real end),0),二季度=isnull(sum(case quarter when 2 
     then real end),0),三季度=isnull(sum(case quarter when 3
      then real end),0),四季度季度=isnull(sum(case quarter when 
      4 then real end),0) from Company 
      group by comid,name 
      

  2.   

    select [Name] ,ISNULL( max(case [quarter] when  1 then [real]  end),0) '第一季度',
    ISNULL(max(case [quarter] when  2 then [real]  end),0) '第二季度',
    ISNULL(max(case [quarter] when 3 then [real]  end),0) '第三季度',
    ISNULL(max(case [quarter] when  4 then [real]  end),0) '第四季度' from dbo.tb1
    group by [Name]