有谁知道为什么下面的 SQL 语句需要永远加载???
select LE_ACNT_STKG.ID_PRD_RP
from
TR_LTM_PHY_CNT
inner join AS_ITM_STK ON (AS_ITM_STK.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT
and AS_ITM_STK.ID_ITM = TR_LTM_PHY_CNT.ID_ITM)
inner join LE_ACNT_STKG ON (LE_ACNT_STKG.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT
and LE_ACNT_STKG.ID_ITM = TR_LTM_PHY_CNT.ID_ITM)
inner JOIN AS_ITM ON (AS_ITM.ID_ITM = AS_ITM_STK.ID_ITM and AS_ITM.ID_STR_RT = AS_ITM_STK.ID_STR_RT)
inner join LO_LCN ON (LE_ACNT_STKG.ID_LCN = LO_LCN.ID_LCN)
INNER JOIN DO_CNT_PHY on TR_LTM_PHY_CNT.ID_DCM_PHY_CNT = DO_CNT_PHY.ID_DCM_PHY_CNT
INNER JOIN CO_EV on (DO_CNT_PHY.ID_STR_RT = CO_EV.ID_STR_RT
and DO_CNT_PHY.ID_EV = CO_EV.ID_EV)
where
LE_ACNT_STKG.ID_PRD_RP >= 4792
AND LE_ACNT_STKG.ID_PRD_RP <= 6693
AND LE_ACNT_STKG.ID_PRD_RP IN (
SELECT TOP 1 LE_ACNT_STKG.ID_PRD_RP
FROM LE_ACNT_STKG
INNER JOIN CA_PRD_RP ON (LE_ACNT_STKG.ID_PRD_RP = CA_PRD_RP.ID_PRD_RP)
WHERE
CA_PRD_RP.TY_PRD_RP = 'CD' AND
LE_ACNT_STKG.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT AND
LE_ACNT_STKG.ID_ITM = TR_LTM_PHY_CNT.ID_ITM AND
(
(CA_PRD_RP.TS_PRD_RP_STRT <= CO_EV.TS_EV_ACT_EF AND CA_PRD_RP.TS_PRD_RP_END >= CO_EV.TS_EV_ACT_EF)
OR --If we're in the latest period, which is still open
(CA_PRD_RP.TS_PRD_RP_STRT <= CO_EV.TS_EV_ACT_EF AND CA_PRD_RP.TS_PRD_RP_END IS NULL)
OR --if there isn't one for the current period, get the previous one
(CA_PRD_RP.TS_PRD_RP_END < CO_EV.TS_EV_ACT_EF)
)
ORDER BY
LE_ACNT_STKG.ID_PRD_RP DESC)
我相信这是因为IN()
子查询。当我取出该语句时,它的加载速度要快得多。如果是这种情况,我该怎么办?我尝试用 替换IN
,EXISTS
但返回的结果完全不同。