2012-03-07 16 views
2
SELECT 
    ITM, OPB, INB, 
    (SELECT CODE FROM CodeandDescription WHERE ITM = RM_S4G100_KYBIN.ITM) As CODE, 
    (SELECT ITMD FROM CodeandDescription WHERE ITM = RM_S4G100_KYBIN.ITM) As ITMD, 
    CLB, DTE 
FROM 
    RM_S4G100_KYBIN 
WHERE 
    (DTE >= '01 Oct 2011') and (DTE <= '31 Oct 2011') 
    AND 
    (SELECT ITMD 
    FROM CodeandDescription 
    WHERE ITM = RM_S4G100_KYBIN.ITM) IS NOT NULL 
    AND 
    (OPB <> '0.00000' OR INB <> '0.00000' OR CLB <> '0.00000') 
ORDER BY 
    ITMD, DTE 

답변

1

CODE 및 ITMD에 대한 추가 SELECT 대신 INNER JOIN을 수행하면 쿼리의 속도가 빨라집니다.

SELECT ITM, OPB, INB, CodeandDescription.CODE As CODE, CodeandDescription.ITMD As ITMD, 
CLB, DTE FROM RM_S4G100_KYBIN INNER JOIN CodeandDescription ON CodeandDescription.ITM = RM_S4G100_KYBIN.ITM 
WHERE (DTE >= '01 Oct 2011') and (DTE <= '31 Oct 2011') and 
CodeandDescription.ITMD is not NULL and 
(OPB <> '0.00000' or INB <> '0.00000' or CLB <> '0.00000') 
ORDER BY ITMD, DTE 
+0

감사합니다. 나는 그것을 시도 할 것이다. – user1254079

+0

고마워요! 그 작품 =) – user1254079