insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over (order by count(1) desc), 
'AttributesPerAttributeCollection', count(1), 
current timestamp, agn_attr_group_id
from agn
where agn_company_id = 40001
and agn_next_version_id = 999999999
group by agn_attr_group_id
;
commit;
