Chapter 9 · Interview Level
58. Follow-Up Visit Chains
Hard40 XPHealthcare
Find visits that have a follow-up date, and count how many subsequent visits (by the same patient with the same doctor) occurred on or after the follow_up_date. Return visit_id, patient_id, doctor_id, visit_date, follow_up_date, and subsequent_visit_count. Only include visits where follow_up_date is not NULL. Order by subsequent_visit_count 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.