insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over (order by count(1) desc), 
'NumeralsPerSecondarySpec' ,
count(1) , current timestamp,  nod_spec_id
from nod, spa, noa
where nod_spec_id = spa_spec_id
and   nod_spec_id = noa_spec_id
and nod_company_id = spa_company_id
and nod_company_id = noa_company_id
and nod_next_version_id = spa_next_version_id
and nod_next_version_id = noa_next_version_id
and nod_id = noa_node_id
and nod_company_id = 40001
and nod_next_version_id = 999999999
and spa_name = 'TYPE'
and spa_value = 'SECONDARY_SPEC'
and nod_type = 'ATTRIBUTE'
and noa_name = 'TYPE'
and noa_value in ('NUMBER','INTEGER')
group by nod_spec_id
;
commit;
