column maxtime format 999.9
column avgtime format 999.9
column iotime format 99,999
column cputime format 99,999
column aptime format 999
column bgets format 999,999
column readkb format 999,999
column reads format 999
select sql.sql_id, plan_hash_value, trunc(begin_interval_time), sum(executions_delta) execs, max(elapsed_time_delta/greatest(executions_delta,1))/1000000 maxtime,  sum(elapsed_time_delta)/sum(greatest(executions_delta,1))/1000000 avgtime, 
  sum(iowait_delta)/sum(greatest(executions_delta,1))/1000 iotime, sum(cpu_time_delta)/sum(greatest(executions_delta,1))/1000 cputime, sum(apwait_delta)/sum(greatest(executions_delta,1))/1000 aptime,
  sum(buffer_gets_delta)/sum(greatest(executions_delta,1)) bgets,   sum(PHYSICAL_READ_BYTES_delta)/sum(greatest(executions_delta,1))/1024 ReadKB
 from dba_hist_sqlstat ss, dba_hist_snapshot snap,
(select sql_id, to_char(substr(sql_text,1,63)) sqltext from dba_hist_sqltext where sql_id = '&sql_id') sql
where ss.snap_id=snap.snap_id and ss.sql_id = sql.sql_id group by sql.sql_id, plan_hash_value, trunc(begin_interval_time) order by 1,3
/
