select riqi,gongsibie
,count(*) as '检验批'
,sum(case panding when 'ok' then 0 else 1 end) as '批退批'
,rtrim(cast(sum(case panding when 'ok' then 0 else 1 end)*1.0/count(*) as decimal(18,2)))+'%' as '批退率'
from wai
group by riqi,gongsibie
,count(*) as '检验批'
,sum(case panding when 'ok' then 0 else 1 end) as '批退批'
,rtrim(cast(sum(case panding when 'ok' then 0 else 1 end)*1.0/count(*) as decimal(18,2)))+'%' as '批退率'
from wai
group by riqi,gongsibie
select 日期=riqi,
公司别=gongsibie,
检验批=count(*),
检验批=sum(case when panding<>'ok' then 1 else o),
批退率=cast(1.00*sum(case when panding<>'ok' then 1 else o)/count(*) as varchar(10))+'%'
from tb
group by riqi,gongsibie
,检验批=count(*)
,批退批=sum(case when panding ='ng' then 1 else 0 end)
,批退率=rtrim(cast(sum(case panding when 'ng' then 1 else 0 end)*1.0/count(*) as decimal(18,2)))+'%'
from wai
group by riqi,gongsibie