Chapter 8 · Window Functions
49. Days Between Consecutive Visits
Hard40 XPHealthcare
For each patient's visits (completed only), calculate the number of days since their previous visit. Return patient_id, visit_date, the previous visit date, and the gap in days. Order by patient_id and visit_date.
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.