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 |