insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over (order by count(1) desc), 
'PopulatedAttributesPerCategory', count(1),
current timestamp, cab_category_id
from cab 
where cab_company_id = 40001
and cab_next_version_id = 999999999
group by cab_category_id
;
commit;
