B
bijiaofan
Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾帮忙看一下这条语句怎这么慢,该加的索引也都加了,查询出来要两到三分钟:<br>SELECT a.rmano,a.PN, a.SN, c.Model AS model,e.maxreturncount,a.returndays, <br>f.test_station,f.test_time,f.repair_time,f.repairer,f.error_code,f.error_desc, <br>g.reason_code,g.reason_desc,f.component,f.location,f.duty FROM RMARecv_d AS a <br>INNER JOIN (SELECT sn,MAX(returncount) AS maxreturncount FROM dbo.RMARecv_d GROUP BY sn ) e <br>ON a.sn=e.sn AND a.returncount=e.maxreturncount <br>INNER JOIN bd_itmstr AS c ON a.PN = c.PN <br>INNER JOIN (SELECT red.partpn AS component ,red.flow_order,red.partloc AS location,red.duty,red.create_t AS create_t,<br>red.sn,red.rmano, (CASE red.pre_station WHEn '3' THEN 'MF/T1' WHen '11' THEN 'MF/T2' WHen '18' THEN 'MF/T3' WHen '10' <br>THEN 'RunIn1' WHen '15' THEN 'RunIn2' WHen '13' THEN 'OBE' WHen '12' THEN 'COSCHECK' WHen '21' THEN 'T00' END ) AS test_station, <br>red.pre_t AS test_time,red.probcd AS error_code,pro.descript AS error_desc,red.start_t AS repair_time,red.rpengfullnm AS repairer <br>FROM RepaLog_d red LEFT OUTER JOIN bd_probcd pro ON red.ProbCd COLLATE Chinese_PRC_CI_AS_WS = pro.ProbCd ) f <br>ON a.sn=f.sn AND a.RMANo=f.rmano INNER JOIN (SELECT rem.flow_order,rem.sn,rem.RMANo,rs.reason AS reason_code,<br>rs.descript AS reason_desc FROM dbo.RepaLog_m rem LEFT OUTER JOIN dbo.bd_reason rs ON <br>rem.result = rs.result AND rem.reason=rs.reason) g ON a.sn=g.sn AND a.RMANo=g.rmano AND g.flow_order=f.flow_order <br>where (f.error_code='4A03') AND (f.repair_time BETWEEN '2008/10/4 8:00:00' AND '2008/11/4 17:00:00') ORDER BY f.repair_time