I'm looking to calculate the percent of times that the patient ("Full_name") has been on-time to their appointment in the query below. In theory I could count out many times the value is "On-time" and how many times its "Late" and devise lates by on times and multiply it by 100 to get the percent but I can't figure out the syntex required to get that calculation to show in a column and then have the patients grouped by their percentage of on-time score.
Example query:
SELECT
Db.Full_Name,
CASE WHEN (Db.DOCTOR_APPOINTMENT_DATE - Db.ARRIVE_DOCTOR_DATE) + (Db.DOCTOR_APPOINTMENT_TIME - Db.ARRIVE_DOCTOR_TIME) < 0 THEN 'LATE' ELSE 'ON-TIME' END AS STATUS,
FROM Db
WHERE Db.DOCTOR_APPOINTMENT_DATE between to_date('10/30/2018','MM/DD/YYYY') and to_date ('12/30/2018','mm/dd/yyyy')
Example Output as currently written:
Full_name: Status:
John Smith On-Time
John Smith On-Time
John Smith Late
John Brown On-Time
John Brown On-Time
James White Late
John Brown On-Time
John Brown Late
James White Late
James White Late
James White On-Time
What I'd like it to do:
Full_Name: % on time:
John Brown 75%
James White 25%
John Smith 66%
Thanks for your time!