就是在不同的状态下计算不同的列 对列累加例如 state=1 就计算A列
     state=2 就计算B列
     state=3 就计算C列
     state=4 就计算D列实际上就是在不同的状态对每个列进行累加
结果应该是
A |B |C |D 2 |3 |4 |5

解决方案 »

  1.   

    o,那就不难了select sum(case when state=1 then 1 else 0 end ) as [A]
     ,sum(case when state=2 then 1 else 0 end ) as [B]
     ,sum(case when state=3 then 1 else 0 end ) as [C]
     ,sum(case when state=4 then 1 else 0 end ) as [D]
    from tableA
      

  2.   

    select sum(case when state=1 then count(a) else 0 end ) as [A]
     ,sum(case when state=2 then count(b) else 0 end ) as [B]
     ,sum(case when state=3 then count(c) else 0 end ) as [C]
     ,sum(case when state=4 then count(d) else 0 end ) as [D]
    from tableA