insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over (order by count(1) desc), 
'EntriesPerLookupTable', count(1) ,
current timestamp, ctg_id
from ctg,itm
where ctg_id = itm_container_id
and ctg_company_id = itm_company_id
and ctg_company_id = 40001
and ctg_type = 'LOOKUP_TABLE'
and itm_next_version_id = 999999999
group by ctg_id
;
commit;
