Write a SQL query using window functions to rank patients by visit count within each clinic and return the top 3 per clinic.
Use the provided clinic, patient, and visit data. Return only patients with at least one visit.
Output
- One row per qualifying patient, with
clinic_name, patient_id, patient_name, visit_count, and clinic_rank
- Include patients whose clinic rank is 1, 2, or 3; tied patients may produce more than three rows for a clinic
- Order by clinic name, rank ascending, then patient ID ascending