行变列

select t.bib_type,
    count(CASE when code.code='BBS001' then t.bib_type end) as Load,
    count(decode(code.code,'BBS001',t.bib_type,'')) as Load,
    count(CASE when code.code='BBS002' then t.bib_type end) as Bi,
    count(CASE when code.code='BBS003' then t.bib_type end) as Unload,
    count(CASE when code.code='BBS004' then t.bib_type end) as Wait,
    count(CASE when code.code='BBS005' then t.bib_type end) as Hold,
    count(CASE when code.code='BBS006' then t.bib_type end) as PM,
    count(CASE when code.code='BBS007' then t.bib_type end) as Clean,
    count(CASE when code.code='BBS008' then t.bib_type end) as Other,
    --count(CASE when code.code='BBS009' then t.bib_type end) as Disabled,
    count(decode(code.code,'BBS009',t.bib_type,'')) as Disabled,
    count(0) total_count,
    round(avg(t.mask_rate),2) mask_rate 
from mcs_bib t,mcs_code_m code 
where t.status=code.code and code.type='BBS' and t.status_code='0' 
group by t.bib_type;

你可能感兴趣的:(sql,bbs)