Write a query using window functions to identify the most recent medical event for each patient in a longitudinal dataset at Garner health.
Use the patients and medical_events tables. Include patients without recorded events, and treat a missing event date as older than any non-null date.
patient_id.patient_id, patient_name, event_id, event_type, and event_date.event_id; use NULLs for patients without an event.| Column | Type | Description |
|---|---|---|
| patient_idPK | INT | Unique patient identifier |
| patient_name | VARCHAR(100) | Patient's display name |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique medical event identifier |
| patient_id | INT | Patient associated with the event |
| event_type | VARCHAR(50) | Category of medical event |
| event_date | DATE | Date on which the medical event occurred |