select 班组,sum1,sum2,sum2/sum1 as 比例 ,sum1-sum2 as sum3 from (SELECT The_group as 班组 , count(case when Q_state='质检通过' or Q_state='质检不通过' then The_group else null end) as sum1, count(case when Q_state='质检通过' and Q_number=1 then The_group else null end) as sum2 FROM "JXS"."KUANDAI" group by The_group ) |