2016-10-05 6 views
0

a와 c는 모두 400 개의 레코드가있는 동일한 테이블입니다. b와 d도 300 개의 레코드가있는 동일한 테이블입니다. 그러나 이것을 실행하는 데 약 4 분이 걸립니다. 어떻게 속도를 높일 수 있습니까?SQL 실행에 너무 오래 걸림

select a.docref 
from a 
left outer b 
on a.cono=b.cono and a.tt=b.tt and a.docref=b.docref 
where a.cono='VC' 
and b.accn08='9005100' 
and a.pstper=11609 
and a.cbpref not in (select c.cbpref 
         from c 
         left outer join d 
         on c.cono=d.cono and c.tt=d.tt and c.docref=d.docref 
         where c.cono='VC' 
         and d.accn08='9005100' 
         and c.pstper=11609 
         and c.tt='RX') 

답변

0

구문 NOT IN은 약간 시간이 걸립니다. LEFT JOIN을 시도한 후 조건을 추가하십시오. ID IS NULL :

SEELCT a.docref 
FROM a 
LEFT OUTER JOIN b 
ON a.cono=b.cono 
AND a.tt=b.tt 
AND a.docref=b.docref 
LEFT OUTER JOIN 
(
    SELECT c.cbpref 
    FROM c 
    LEFT OUTER JOIN d 
    ON c.cono=d.cono AND c.tt=d.tt AND c.docref=d.docref 
    WHERE c.cono='VC' 
    AND d.accn08='9005100' 
    AND c.pstper=11609 
    AND c.tt='RX' 
)tb 
ON tb.cbpref = a.cbpref 
AND a.cbpref IS NULL 
WHERE a.cono='VC' 
AND b.accn08='9005100' 
AND a.pstper=11609 
관련 문제