Show Top SQL by Execution for a Given date Time
-- -- Show Top SQL by Execution for a Given date Time -- WITH snaps AS ( SELECT MIN(a.snap_id) AS min_snap, MAX(a.snap_id) AS max_snap FROM DBA_HIST_SNAPSHOT a WHERE a.end_interval_time BETWEEN TO_TIMESTAMP('24/01/2019 07:00:00.000','DD/MM/YYYY HH24:MI:SS.FF') AND TO_TIMESTAMP('24/01/2019 08:02:00.000','DD/MM/YYYY HH24:MI:SS.FF') ), sqlcount as ( SELECT a.sql_id, SUM(a.executions_delta) AS total_executions FROM DBA_HIST_SQLSTAT a, SNAPS b WHERE a.snap_id BETWEEN b.min_snap+1 AND b.max_snap GROUP BY a.sql_id HAVING SUM(a.executions_delta)>100 ) SELECT a.sql_id,b. sql_text, a.total_executions FROM SQLCOUNT a, DBA_HIST_SQLTEXT b, V$DATABASE c WHERE a.sql_id=b.sql_id AND b.dbid=c.dbid ORDER BY 3 DESC