select
type,
sum(case when status='pass'  then 1 else 0 end) as ct
from 
T
group by type

解决方案 »

  1.   

    select ct = sum(case status when 'pass' then 1 else 0 end), type from temp group by type
      

  2.   

    select type , sum(case amount when 'pass' then 1 else 0 end) as ct from temp group by type
      

  3.   

    select type , sum(case amount when 'pass' then 1 else 0 end) as ct from temp group by type
      

  4.   


     select 
        sum(case amount                          }对amount进行判断
                 when 'pass' then 1              }假如通过的就为1
                             else 0              }没通过就为0
                     end ) as ct                 }最后sum()将其相加,得到你想要的结果
    ,type from temp
               group by type                     }把type中的值进行分组
         
         
      

  5.   


    create table tb(Pid int,type varchar(10),amount varchar(10))
    insert into tb select 1,'A','Pass'
    insert into tb select 2,'A','Pass'
    insert into tb select 3,'A','Pass'
    insert into tb select 4,'B','Pass'
    insert into tb select 5,'C','unPass'
    insert into tb select 6,'D','Pass'select type,ct=(select count(1) from tb where a.type=type and amount='Pass' ) from tb a
    group by type