–SQL_ID에 위에서 추출한 SQL_ID를 입력후 수행한다.
SELECT RST.BEGIN_INTERVAL_TIME
,RST.SQL_ID
,(SELECT SQL_OPNAME
FROM OWNER.TB_DBA_SQL_HIST_DETAIL X
WHERE X.SQL_ID = RST.SQL_ID
AND ROWNUM <= 1) SQL_TYPE
,TO_NUMBER(LISTAGG(DECODE(RST.INSTANCE_NUMBER, 1, RST.EXECUTIONS, NULL))) NODE_1
,TO_NUMBER(LISTAGG(DECODE(RST.INSTANCE_NUMBER, 2, RST.EXECUTIONS, NULL))) NODE_2
,TO_NUMBER(LISTAGG(DECODE(RST.INSTANCE_NUMBER, 3, RST.EXECUTIONS, NULL))) NODE_3
,TO_NUMBER(LISTAGG(DECODE(RST.INSTANCE_NUMBER, 4, RST.EXECUTIONS, NULL))) NODE_4
FROM ( SELECT A.INSTANCE_NUMBER
,TO_CHAR(B.BEGIN_INTERVAL_TIME, 'YYYY/MM/DD HH24') BEGIN_INTERVAL_TIME
,A.SQL_ID
,SUM(A.EXECUTIONS_DELTA) EXECUTIONS
FROM DBA_HIST_SQLSTAT A,
(SELECT INSTANCE_NUMBER
,SNAP_ID
,BEGIN_INTERVAL_TIME
,END_INTERVAL_TIME
FROM DBA_HIST_SNAPSHOT
) B
WHERE 1=1
AND A.SNAP_ID = B.SNAP_ID
AND A.INSTANCE_NUMBER = B.INSTANCE_NUMBER
AND (A.MODULE IN ('JDBC Thin Client', 'SQL*Plus')
OR A.MODULE LIKE 'FC%'
OR A.MODULE LIKE 'sqlplus%'
)
AND TO_CHAR(B.BEGIN_INTERVAL_TIME, 'YYYYMMDDHH24') >= TO_CHAR(SYSDATE-30, 'YYYYMMDD') --1 MONTH
AND A.SQL_ID IN ( 'sql_id'
,'sql_id'
,'sql_id'
)
GROUP BY A.INSTANCE_NUMBER
,TO_CHAR(B.BEGIN_INTERVAL_TIME, 'YYYY/MM/DD HH24')
,A.SQL_ID
ORDER BY BEGIN_INTERVAL_TIME
) RST
GROUP BY RST.BEGIN_INTERVAL_TIME, RST.SQL_ID
ORDER BY RST.BEGIN_INTERVAL_TIME;