SELECT COUNT(*) AS ct
FROM TABLEA _tablea
LEFT OUTER JOIN
(SELECT DISTINCT CM_CASE_ID,
LOG_TIMESTAMP,
ACTION_PERFORMED_BY,
CASE_FOLLOW_UP_DATE,
ACTION_PICKLIST_ID,
CASE_REQUEST_NOTE_VALUE,
CASE_STATUS_ID,
RESOLUTION_PICKLIST_ID,
PREVIOUS_REQUEST_OWNER,
CURRENT_REQUEST_OWNER,
CASE_FOLLOW_UP_NOTE_VALUE,
CM_PENDING_REASON_ID,
ACCOUNT_STATUS
FROM TABLEB _tableb
WHERE _tableb.LOG_TIMESTAMP
||_tableb.CM_CASE_ID IN
(SELECT MIN(_tableb.LOG_TIMESTAMP)
||_tableb.CM_CASE_ID AS col_0_0_
FROM TABLEB _tableb
WHERE _tableb.CASE_STATUS_ID='A'
GROUP BY _tableb.CM_CASE_ID
)
) _tableb
ON _tablea.CM_CASE_ID=_tableb.CM_CASE_ID
WHERE _tablea.CASE_CREATION_DATE BETWEEN to_date('12/01/2016', 'mm/dd/yyyy') AND to_date('06/07/2017', 'mm/dd/yyyy') + 1
AND _tablea.CASE_REQUEST_TYPE IN (1,2,3)
AND _tablea.CASE_STATUS_ID IN ('A','B')
上述查询预计在2016年1月12日至2017年7月6日之间的记录可以在更短的时间内正常工作
SELECT COUNT(*) AS ct
FROM TABLEA _tablea
LEFT OUTER JOIN
(SELECT DISTINCT CM_CASE_ID,
LOG_TIMESTAMP,
ACTION_PERFORMED_BY,
CASE_FOLLOW_UP_DATE,
ACTION_PICKLIST_ID,
CASE_REQUEST_NOTE_VALUE,
CASE_STATUS_ID,
RESOLUTION_PICKLIST_ID,
PREVIOUS_REQUEST_OWNER,
CURRENT_REQUEST_OWNER,
CASE_FOLLOW_UP_NOTE_VALUE,
CM_PENDING_REASON_ID,
ACCOUNT_STATUS
FROM TABLEB _tableb
WHERE _tableb.LOG_TIMESTAMP
||_tableb.CM_CASE_ID IN
(SELECT MIN(_tableb.LOG_TIMESTAMP)
||_tableb.CM_CASE_ID AS col_0_0_
FROM TABLEB _tableb
WHERE _tableb.CASE_STATUS_ID='A'
GROUP BY _tableb.CM_CASE_ID
)
) _tableb
ON _tablea.CM_CASE_ID=_tableb.CM_CASE_ID
WHERE _tablea.CASE_CREATION_DATE BETWEEN to_date('05/01/2017', 'mm/dd/yyyy') AND to_date('06/07/2017', 'mm/dd/yyyy') + 1
AND _tablea.CASE_REQUEST_TYPE IN (1,2,3)
AND _tablea.CASE_STATUS_ID IN ('A','B')
这个预计在2017年1月5日至2017年7月6日期间记录的查询花费了大约20分钟的时间......
请帮助解释为什么期望更多结果的查询工作正常而不是更少。
答案 0 :(得分:0)
;with cte_tablea as (
SELECT CM_CASE_ID, CASE_CREATION_DATE,
CASE_REQUEST_TYPE , CASE_STATUS_ID
FROM TABLEA )
,cte_tableb as (
SELECT DISTINCT CM_CASE_ID,
LOG_TIMESTAMP,
ACTION_PERFORMED_BY,
CASE_FOLLOW_UP_DATE,
ACTION_PICKLIST_ID,
CASE_REQUEST_NOTE_VALUE,
CASE_STATUS_ID,
RESOLUTION_PICKLIST_ID,
PREVIOUS_REQUEST_OWNER,
CURRENT_REQUEST_OWNER,
CASE_FOLLOW_UP_NOTE_VALUE,
CM_PENDING_REASON_ID,
ACCOUNT_STATUS
FROM TABLEB
)
SELECT COUNT(*) AS ct
FROM cte_tablea _tablea
LEFT OUTER JOIN
cte_tablea _tableb
on _tablea.CM_CASE_ID=_tableb.CM_CASE_ID
WHERE _tableb.LOG_TIMESTAMP
||_tableb.CM_CASE_ID IN
(SELECT MIN(_tableb.LOG_TIMESTAMP)
||_tableb.CM_CASE_ID AS col_0_0_
FROM TABLEB cte_tablea
WHERE _tableb.CASE_STATUS_ID='A'
GROUP BY _tableb.CM_CASE_ID
)
and _tablea.CASE_CREATION_DATE BETWEEN to_date('05/01/2017',
'mm/dd/yyyy') AND to_date('06/07/2017', 'mm/dd/yyyy') + 1
AND _tablea.CASE_REQUEST_TYPE
IN (1,2,3)
AND _tablea.CASE_STATUS_ID IN ('A','B')