select 跟踪单号 , b.pm,b.sh,b.wkgg,b.wbxh,b.ljxh,b.khmc,b.chcpmc,b.ms, sum(case when 生产部门='打包' then 1 else 0 end ) 打包,
sum(case when 生产部门= '二次曝光' then 1 else 0 end)二次曝光,
sum(case when 生产部门= '膜厚' then 1 else 0 end)膜厚,
sum(case when 生产部门= '晒版' then 1 else 0 end)晒版,
sum(case when 生产部门= '物控' then 1 else 0 end)物控 ,
sum(case when 生产部门= '涂布' then 1 else 0 end)涂布 ,
sum(case when 生产部门= '脱脂' then 1 else 0 end)脱脂,
sum(case when 生产部门= '显影' then 1 else 0 end)显影,
sum(case when 生产部门= '一检' then 1 else 0 end)一检
from 生产 a ,wbgzd b where 在手='0' and 生产部门 not in('物控仓库','物控') and a.跟踪单号=b.gzdh group by 跟踪单号 , b.pm,b.sh,b.wkgg,b.wbxh,b.ljxh,b.khmc,b.chcpmc,b.ms