I am trying to show a percentage of total payments that were in Time from the total results returned when running the following SQL query:
SELECT job.job_number, claim_job.contract_code, claim_job.claim_code, job.actual_comp_date, claim_header.claim_date, (CASE WHEN trunc(job.actual_comp_date,'DD') - trunc(claim_header.claim_date,'DD') >=28 THEN 'YES' WHEN trunc(job.actual_comp_date,'DD') - trunc(claim_header.claim_date,'DD') < 27 THEN 'NO' ELSE 'Unknown' END) as Late, trunc(job.actual_comp_date,'DD') - trunc(claim_header.claim_date,'DD') as Datediff FROM job LEFT OUTER JOIN claim_job ON job.contract_code = claim_job.contract_code AND job.order_number = claim_job.order_number AND job.job_number = claim_job.order_job_number LEFT OUTER JOIN claim_header ON claim_header.contract_code = claim_job.contract_code AND claim_header.claim_code = claim_job.claim_code
-------------------------------------
The identifier if a job is in time is the bold bit of the expression above.
When this query is run the SQL could return an unknown number of results so I am trying to figure out how to get the percentage of total results where the payment was in time (i.e. where Late = No).