我使用 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