insert into metadata_statistics(rundate, metadata_defn, order_sequence, total_entries, metadata_id) 
select to_date(sysdate,'YYYY-MM-DD-HH24:MI:SS'), 'CategorizationsPerItem', rownum, totals, id from 
(select count(1) totals, icm_item_id id
from icm
where icm_company_id = 40001
and icm_next_version_id = 999999999
group by icm_item_id
order by count(1) desc
) ;
commit;
quit;
