select
to_char(snp.end_interval_time, 'yyyy-mm-dd hh24:mi:ss') tm,
max(case when mem.name = 'KGLDA' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) KGLDA_gb,
max(case when mem.name = 'KGLH0' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) KGLH0_gb,
max(case when mem.name = 'KGLHD' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) KGLHD_gb,
max(case when mem.name = 'SQLA' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) SQLA_gb,
max(case when mem.name = 'fixed_sga' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) fixed_sga_gb,
max(case when mem.name = 'buffer_cache' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) buffer_cache_gb,
max(case when mem.name = 'db_block_hash_buckets' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) db_block_hash_buckets_gb,
max(case when mem.name = 'free memory' and mem.pool='java pool' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) java_pool_free_gb,
max(case when mem.name = 'free memory' and mem.pool='large pool' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) large_pool_free_gb,
max(case when mem.name = 'free memory' and mem.pool='streams pool' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) streams_pool_free_gb,
max(case when mem.name = 'free memory' and mem.pool='shared pool' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) shared_pool_free_gb,
max(case when mem.name = 'row cache' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) row_cache_gb,
max(case when mem.name = 'session heap' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) session_heap_gb,
max(case when mem.name = 'simulator hash buckets' then to_char(mem.bytes/1024/1024/1024, '99,990.0') end) simulator_hash_buckets_gb
/*
mem.instance_number,
mem.dbid,
mem.snap_id,
mem.con_dbid,
mem.con_id
*/
from
dba_hist_sgastat mem join
dba_hist_snapshot snp on mem.snap_id = snp.snap_id and
mem.dbid = snp.dbid
group by
to_char(snp.end_interval_time, 'yyyy-mm-dd hh24:mi:ss')
order by
to_char(snp.end_interval_time, 'yyyy-mm-dd hh24:mi:ss') desc;