Your question is Top 10 Patients by Visits. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Massachusetts General Hospital needs a patient-volume report for operational planning. Write a PostgreSQL query that identifies the 10 patients with the most qualifying visits recorded during calendar year 2025.
2025-01-01 through 2025-12-31.Cancelled or is NULL.patient_id ascending as a deterministic tie-breaker.| Column | Type | Description |
|---|---|---|
| patient_idPK | INTEGER | Unique patient identifier |
| first_name | VARCHAR(50) | Patient first name |
| last_name | VARCHAR(50) | Patient last name |
| date_of_birth | DATE | Patient date of birth |
| Column | Type | Description |
|---|---|---|
| visit_idPK | INTEGER | Unique visit identifier |
| patient_id | INTEGER | Patient associated with the visit |
| visit_date | DATE | Date of the visit |
| status | VARCHAR(20) | Visit status |
| encounter_type | VARCHAR(30) | Type of clinical encounter |