UT_PINOUT 테이블은 10000번 공정에서 완성되어 OUT으로 만들어진 ID 'KJX3I1234' 가
20000번 공정으로 IN(투입) 되는 용도의 테이블인데요..
아래 쿼리를 좀 더 오라클 함수를 써서 쿼리 속도를 좀 개선하고 싶은데..
UT_PINOUT 테이블안에 데이터가 무척 많거든요...자꾸 이 쿼리로 문제가 생겨서...
2주 고민하고 글 등록합니다...
도움 요청합니다. 고수님들 지혜를 모아주세요..ㅜㅜ
SELECT A.LARGEDATA
,A.FLOT
,A.SUBID
,A.PRODID
,A.QTY
,A.MODELID
,A.REGDATE
,B.FLOT
,DECODE(B.FLOT,null,'2','1') AS RANK
FROM
(SELECT TO_CHAR(C.REGDATE,'YYYYmmDD') AS LARGEDATA
,C.LOTID AS FLOT
,B.SUBID AS SUBID
,B.PRODID AS PRODID
,A.QTY AS QTY
,B.MODELID AS MODELID
,B.REGDATE AS REGDATE
FROM UT_PWIP A
,UT_PLOT B
,LOT C
,PRODUCT D
WHERE A.PROCID = '20000'
AND A.SUBID = B.SUBID
AND B.LOTID = C.LOTID
AND C.LOTTYPE = 'F'
AND A.PRODID = D.PRODID(+)
AND B.MODELID IN (SELECT B.MODELID
FROM UT_PWIP A, PRODUCT_MODEL B
WHERE A.SUBID = 'KJX3I1234'
AND A.PRODID = B.PRODID
)
) A,
(SELECT /*+ no_merge(A)*/ DISTINCT A.FLOT
FROM (SELECT A.FLOT , B.SUBID
FROM (SELECT DISTINCT C.LOTID AS FLOT
FROM UT_PWIP A
,UT_PLOT B
,LOT C
,PRODUCT D
WHERE A.PROCID = '20000'
AND A.SUBID = B.SUBID
AND B.LOTID = C.LOTID
AND C.LOTTYPE = 'F'
AND A.PRODID = D.PRODID(+)
AND B.MODELID IN (SELECT B.MODELID
FROM UT_PWIP A, PRODUCT_MODEL B
WHERE A.SUBID = 'KJX3I1234'
AND A.PRODID = B.PRODID
)
) A, UT_PINOUT B
WHERE A.FLOT = B.LOTID
AND B.PROCID = '10000'
AND B.INOUTTYPE = 'OUT') A ,UT_PINOUT B
WHERE A.SUBID = B.SUBID
AND B.LOTTYPE = 'B'
AND B.INOUTTYPE = 'IN'
AND B.REGDATE > SYSDATE - 7) B
WHERE A.FLOT = B.FLOT(+)
ORDER BY RANK, LARGEDATA, A.FLOT, SUBID
SELECT TO_CHAR(c.regdate,'yyyymmdd') AS largedata , c.lotid AS flot , b.subid AS subid , b.prodid AS prodid , a.qty AS qty , b.modelid AS modelid , b.regdate AS regdate , (SELECT NVL(MIN(1), 2) FROM ut_pinout bb , ut_pinout bbb WHERE bb.lotid = b.lotid AND bb.procid = '10000' AND bb.inouttype = 'OUT' AND bbb.subid = bb.subid AND bbb.lottype = 'B' AND bbb.inouttype = 'IN' AND bbb.regdate > sysdate - 7 AND ROWNUM <= 1 ) AS rank FROM ut_pwip a , ut_plot b , lot c , product d WHERE a.procid = '20000' AND a.subid = b.subid AND b.lotid = c.lotid AND c.lottype = 'F' AND a.prodid = d.prodid(+) AND b.modelid IN (SELECT b.modelid FROM ut_pwip a , product_model b WHERE a.subid = 'KJX3I1234' AND a.prodid = b.prodid ) ORDER BY rank, largedata, flot, subid ;