Chapter 5 · JOINs
72. Patients with Visits Within 30 Days of a Previous Visit
Medium20 XPHealthcare
Identify potential readmissions by finding patients who had two visits within 30 days of each other. Return the patient's first name, last name, the first visit date, the second visit date, and the number of days between them. Each pair should appear only once. Sort by days_between ascending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- date_of_birthTEXT
- genderTEXT
- emailTEXT
- phoneTEXT
- blood_typeTEXT
- cityTEXT
- stateTEXT
- FKinsurance_id→ insurance.idINT
- created_atTIMESTAMP
- 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.