SELECT RIQI,QAC011,QAC009,QAC003,QAC005,QAC006,QAC007,LPS,(CASE WHEN BLS IS NULL THEN '0'ELSE BLS END) AS BLS, CASE WHEN BLS IS NULL THEN '0%' WHEN LPS = 0 THEN '100%' WHEN BLS != 0 THEN concat(cast(ROUND(BLS*1.00/(LPS+BLPS)*100,2) as decimal(10,2)),'%') END AS BLL FROM (SELECT LEFT(QAC017,10) AS RIQI,QAC011,QAC009,QAC003,QAC005,QAC006,QAC007,SUM(QAC019)LPS,SUM(QAC020)BLPS FROM WOMQAC WHERE QAC009 NOT IN ('包装','包装投入','AI投入','curGXMC','DIP投 入','FQC') GROUP BY LEFT(QAC017,10),QAC011,QAC009,QAC003,QAC005,QAC006,QAC007) AS A /*投入时间 线别 工序名称 指定单号 产品编码 产品名称 产品规格 */ LEFT JOIN ( SELECT case when len(CREATETIME) = 19 then substring(CREATETIME,1,10) when len(CREATETIME) = 14 then concat(substring(CREATETIME,1,4),'-',substring(CREATETIME,5,2),'-',substring(CREATETIME,7,2)) end AS RQ, QAI007,QAI008,QAI009,COUNT(QAI002) BLS FROM WOMQAI GROUP BY case when len(CREATETIME) = 19 then substring(CREATETIME,1,10) when len(CREATETIME) = 14 then concat(substring(CREATETIME,1,4),'-',substring(CREATETIME,5,2),'-',substring(CREATETIME,7,2)) end,QAI007,QAI008,QAI009 ) AS B ON A.QAC003 = B.QAI008 AND A.QAC011 = B.QAI007 AND A.RIQI = B.RQ 需要 按每天8:00到第二天8:00分类算出这天的LPS |