Chapter 8 · Window Functions
56. Cumulative Visit Count per Doctor Over Time
Hard40 XPHealthcare
For each doctor, compute a running count of their visits ordered by visit_date. Return doctor full name, visit_date, diagnosis, and cumulative_visit_num (the Nth visit for that doctor). Visits on the same date are numbered in visit id order. Order by doctor_name, then cumulative_visit_num.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- specialtyTEXT
- FKdepartment_id→ departments.idINT
- emailTEXT
- phoneTEXT
- hire_dateTEXT
- salaryREAL
- 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.