break on country skip 1 compute sum of downtime on country define start_date ="trunc((get_date('MONTH','START') - 1),'MONTH') + 12/24" define end_date="trunc(trunc(get_date('MONTH','START'),'MONTH'),'DD')+ 12/24" define percent="((1 - (sum(NVL(ncl.downtime_secs,0))/sum(date_seconds_between(&end_date,&start_date)))) * 100)" spool ${spool_file} set markup html on spool on select sd.site_name, sum(NVL(ncl.downtime_secs,0)) downtime, (case when &percent < 100 then to_char(&percent,99.99999) else to_char(&percent,999) end) availability, convert_seconds_to_dhms(sum(NVL(ncl.downtime_secs,0))) downtime_dhms from ncl_summary_tmp ncl, (select distinct contracted_node_name, site_name from contracted_nodes ) cn, site_details sd where UPPER(SUBSTR(ncl.node (+) ,0,(INSTR(ncl.node (+),'.') -1))) = cn.contracted_node_name and sd.site_name = cn.site_name having &percent < 100 group by sd.site_name order by downtime