Chapter 6 · Subqueries
39. Diagnosis Frequency as Percentage
Medium20 XPHealthcare
Medical research wants to know the distribution of diagnoses. For each diagnosis, return the diagnosis, count, and what percentage of all visits it represents (as pct, rounded to 1 decimal). Order by pct descending.
Tables
- PKidINT
- FKpatient_id→ patients.idINT
- FKdoctor_id→ doctors.idINT
- visit_dateTEXT
- diagnosisTEXT
- notesTEXT
- follow_up_dateTEXT
- statusTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.