Chapter 5 · JOINs
61. Number of Lab Tests per Visit
Medium20 XPHealthcare
The lab director wants to know how many tests are ordered per visit on average. Return the visit_id, visit_date, diagnosis, and test_count for each visit that had lab tests. Order by test_count descending, then visit_date.
Tables
- PKidINT
- FKpatient_id→ patients.idINT
- FKdoctor_id→ doctors.idINT
- visit_dateTEXT
- diagnosisTEXT
- notesTEXT
- follow_up_dateTEXT
- statusTEXT
- PKidINT
- FKvisit_id→ visits.idINT
- test_nameTEXT
- result_valueTEXT
- unitTEXT
- reference_rangeTEXT
- is_abnormalINT
- tested_atTEXT
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.