insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over (order by count(1) desc), 
'StandAloneSpecsPerCategory', count(1) ,
current timestamp, csa_category_id
from csa 
where csa_company_id = 40001 
and csa_name = 'CATEGORY_SPEC_ID' 
and csa_next_version_id = 999999999 
group by csa_category_id
;
commit;
