insert into metadata_statistics(rundate, metadata_defn, order_sequence, total_entries, metadata_id) 
select to_date(sysdate,'YYYY-MM-DD-HH24:MI:SS'), 'NumeralsPerSecondarySpec', rownum, totals, id from 
(select count(1) totals, nod_spec_id 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
order by totals desc);
commit;
quit;
