Write a SQL query using window functions to rank patients by risk score within each hospital and return the top 3 per hospital.
Use the patients and hospitals tables. Include only patients with recorded risk scores. Ties are broken by the lower patient_id.
hospital_id, hospital_name, patient_id, patient_name, risk_score, and risk_rank.hospital_id and risk_rank ascending.| Column | Type | Description |
|---|---|---|
| hospital_idPK | INT | Unique hospital identifier |
| hospital_name | VARCHAR(100) | Hospital name |
| Column | Type | Description |
|---|---|---|
| patient_idPK | INT | Unique patient identifier |
| hospital_id | INT | Hospital responsible for the patient |
| patient_name | VARCHAR(100) | Patient name |
| risk_score | DECIMAL(5,2) | Calculated patient risk score |