Write a SQL query to find the top-ranked patients by number of visits within each clinic.
Use the clinics, patients, and visits tables. Count every visit record, including visits with a NULL visit date. Patients without visits and clinics without qualifying patients should not appear.
Output
- One row per top-ranked patient within a clinic.
- Columns:
clinic_id, clinic_name, patient_id, patient_name, visit_count, and patient_rank.
- Include all patients tied for the highest visit count in their clinic. Order by
clinic_id, then patient_id.