select count(a01) from b_feedback_new where a01=1 and airtime>= 20090101 and airtime<= 20090501
select  count(a01) from b_feedback_new where a01!=0 and airtime>= 20090101 and airtime<=20090501 
1为合格 2为不合格  0不参与  两者相除在*100就是合格率
求完整的合格率SQL 

解决方案 »

  1.   

    SELECT SUM(DECODE(A01,
                      1,
                      1,
                      0)) / SUM(DECODE(A01,
                                       1,
                                       1,
                                       2,
                                       1,
                                       0,
                                       0)) * 100 AS 合格率 
      FROM B_FEEDBACK_NEW
     WHERE AIRTIME >= 20090101
       AND AIRTIME <= 20090501
      

  2.   

    select 
    count(case when a01=1 then 1 else 0 end),
    count(case when a01=2 then 1 else 0 end),
    count(case when a01=1 then 1 else 0 end)/count(case when a01=2 then 1 else 0 end)
    from b_feedback_new 
    where airtime>= 20090101 and airtime <=20090501