SELECT 年度,月份,计划,SUM(不良数量)/SUM(CASE WHEN 切断数量>0 THEN 切断数量 ELSE 1 END)不良率 FROM( SELECT 年度,月份,计划,ISNULL(切断数,'0')切断数量,SUM(不良数量)不良数量 FROM( SELECT YEAR(A.finish_date)年度,MONTH(A.finish_date)月份,'0.003' AS 计划,e.description 物料描述,A.lot 制造号, (case when wc='c' then SUM(qty) end )切断数, (case when wc='d' then SUM(qty) end )锻造数, C.description 不良描述,B.qty_bad 不良数量 FROM work_trans A left join work_trans_qc b on a.id=b.work_trans_id LEFT join reason_code_base c on b.reason_code=c.reason_code LEFT join in_product d on a.lot=d.lot LEFT join item e on d.item=e.item WHERE A.finish_date>='2019/8/1' AND A.finish_date<$月份 GROUP BY A.finish_date,e.description,A.lot,C.description,B.qty_bad,wc )AA GROUP BY 年度,月份,计划,切断数 )BB WHERE 1=1 ${if(len(年度)== 0,""," and 年度 = '" + 年度 +"'")} ${if(len(月份)== 0,""," and 月份 = '" + 月份 +"'")} GROUP BY 年度,月份,计划 "A.finish_date<$月份" 这里出错 |