Your question is SQL Time Between Visits. Start with the requirements and the one table 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.
Tempus Lens uses longitudinal patient records to support clinical insights. Given a patient visit table, write a PostgreSQL query that measures the interval between each patient's first and second completed visits.
visit_status = 'completed' and a non-null visit_started_at.visit_id to break timestamp ties.patient_id.| Column | Type | Description |
|---|---|---|
| visit_idPK | INT | Unique identifier for the visit |
| patient_id | INT | Identifier of the patient receiving care |
| visit_started_at | TIMESTAMP | Timestamp when the visit started |
| visit_status | VARCHAR(20) | Status or outcome of the visit |