我使用with語句和兩個查詢重新編寫了查詢。工作得非常快,並給我正確的結果。
WITH FRST
AS ( SELECT D_DTM,
BSM_NM,
SUM (V_ATT_CNT) AS "V_ATT_CNT",
SUM (V_CUST_BLK_CNT) AS "V_CUST_BLK_CNT",
SUM (V_DRP_CALL_CNT) AS "V_DRP_CALL_CNT",
SUM (D_ATT_CNT) AS "D_ATT_CNT",
SUM (D_CUST_BLK_CNT) AS "D_CUST_BLK_CNT",
SUM (D_DRP_CALL_CNT) AS "D_DRP_CALL_CNT"
FROM DMSN.DS3R_FH_1XRTT_FA_LVL_KPI
WHERE D_DTM >=
(SELECT MAX (D_DTM) - NUMTODSINTERVAL (12, 'HOUR')
FROM DMSN.DS3R_FH_1XRTT_FA_LVL_KPI)
GROUP BY D_DTM, BSM_NM),
LST
AS ( SELECT D_DTM,
BSM_NM,
SUM (V_ATT_CNT) AS "V_ATT_CNT",
SUM (V_CUST_BLK_CNT) AS "V_CUST_BLK_CNT",
SUM (V_DRP_CALL_CNT) AS "V_DRP_CALL_CNT",
SUM (D_ATT_CNT) AS "D_ATT_CNT",
SUM (D_CUST_BLK_CNT) AS "D_CUST_BLK_CNT",
SUM (D_DRP_CALL_CNT) AS "D_DRP_CALL_CNT"
FROM DMSN.DS3R_FH_1XRTT_FA_LVL_KPI
WHERE D_DTM >=
(SELECT MAX (D_DTM) - NUMTODSINTERVAL (48, 'HOUR')
FROM DMSN.DS3R_FH_1XRTT_FA_LVL_KPI)
GROUP BY D_DTM, BSM_NM),
EVDOLST
AS ( SELECT D_DTM,
BSM_NM,
SUM (ATT_CNT) AS "ATT_CNT",
SUM (CUST_BLK_CNT) AS "CUST_BLK_CNT",
SUM (DRP_CALL_CNT) AS "DRP_CALL_CNT"
FROM DMSN.DS3R_FH_EVDO_FA_LVL_KPI
WHERE D_DTM >=
(SELECT MAX (D_DTM) - NUMTODSINTERVAL (48, 'HOUR')
FROM DMSN.DS3R_FH_EVDO_FA_LVL_KPI)
GROUP BY D_DTM, BSM_NM),
EVDOFRST
AS ( SELECT D_DTM,
BSM_NM,
SUM (ATT_CNT) AS "ATT_CNT",
SUM (CUST_BLK_CNT) AS "CUST_BLK_CNT",
SUM (DRP_CALL_CNT) AS "DRP_CALL_CNT"
FROM DMSN.DS3R_FH_EVDO_FA_LVL_KPI
WHERE D_DTM >=
(SELECT MAX (D_DTM) - NUMTODSINTERVAL (12, 'HOUR')
FROM DMSN.DS3R_FH_EVDO_FA_LVL_KPI)
GROUP BY D_DTM, BSM_NM)
SELECT t1.D_DTM,
t1.BSM_NM,
t2.V_ATT_CNT AS "LASTV_ATTCNT",
t2.V_CUST_BLK_CNT AS "LASTV_BLKCNT",
t2.V_DRP_CALL_CNT AS "LASTV_DRPCNT",
t1.V_ATT_CNT AS "V_ATT_CNT",
t1.V_CUST_BLK_CNT AS "V_CUST_BLK_CNT",
t1.V_DRP_CALL_CNT AS "V_DRP_CALL_CNT",
t2.D_ATT_CNT AS "LASTD_ATTCNT",
t2.D_CUST_BLK_CNT AS "LASTD_BLKCNT",
t2.D_DRP_CALL_CNT AS "LASTD_DRPCNT",
t1.D_ATT_CNT AS "D_ATT_CNT",
t1.D_CUST_BLK_CNT AS "D_CUST_BLK_CNT",
t1.D_DRP_CALL_CNT AS "D_DRP_CALL_CNT",
t3.ATT_CNT AS "EVDO_ATTCNT",
t3.CUST_BLK_CNT AS "EVDO_BLKCNT",
t3.DRP_CALL_CNT AS "EVDO_DRPCNT",
t4.ATT_CNT AS "EVDO_LASTATTCNT",
t4.CUST_BLK_CNT AS "EVDO_LASTBLKCNT",
t4.DRP_CALL_CNT AS "EVDO_LASTDRPCNT"
FROM FRST t1
INNER JOIN LST t2
ON t1.BSM_NM = t2.BSM_NM
AND t1.D_DTM - NUMTODSINTERVAL (24, 'HOUR') = t2.D_DTM
LEFT OUTER JOIN EVDOLST t4
ON t1.BSM_NM = t4.BSM_NM
AND t1.D_DTM - NUMTODSINTERVAL (24, 'HOUR') = t4.D_DTM
LEFT OUTER JOIN EVDOFRST t3
ON t1.BSM_NM = t3.BSM_NM AND t1.D_DTM = t3.D_DTM
這種情況'D_DTM =(D_DTM-24/24)'總是FALSE。 – 2013-04-22 20:06:00
您的查詢是錯誤的,很難閱讀。您需要添加示例數據。 – Art 2013-04-22 20:54:21
什麼數據類型是'D_DTM'? – 2013-05-10 13:52:15