以下SQL需要很长时间才能执行。反正有加速吗?

时间:2012-03-07 07:37:12

标签: sql sql-server tsql

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 个答案:

答案 0 :(得分:1)

如果您执行INNER JOIN而不是CODE和ITMD的其他SELECT,那么应该加快查询速度。

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