How would you use ROW_NUMBER to identify the latest record per patient or device?
Write a PostgreSQL query using the patient_device_records table. Treat recorded_at as the primary recency field and record_id as the tie-breaker when timestamps match. Exclude rows without an entity identifier.
entity_type, entity_id, record_id, recorded_at, status, and measurement_valueentity_type, then entity_id| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique record identifier |
| entity_type | VARCHAR(20) | Whether the record belongs to a patient or device |
| entity_id | VARCHAR(30) | Patient or device identifier |
| recorded_at | TIMESTAMP | Timestamp when the record was captured |
| status | VARCHAR(30) | Status associated with the record |
| measurement_value | DECIMAL(8,2) | Recorded measurement value |