Write a SQL query using window functions to find each patient’s most recent claim and the previous claim date for Cohere Health data.
Use the provided patients and claims tables. Include patients with at least one claim, use claim_id as the tie-breaker when claim dates match, and exclude unmatched claims.
patient_id, patient_name, most_recent_claim_id, most_recent_claim_date, and previous_claim_datepatient_id ascending| Column | Type | Description |
|---|---|---|
| patient_idPK | INT | Unique patient identifier |
| patient_name | VARCHAR(100) | Patient display name |
| Column | Type | Description |
|---|---|---|
| claim_idPK | INT | Unique claim identifier |
| patient_id | INT | Patient associated with the claim |
| claim_date | DATE | Date the claim was submitted |
| claim_status | VARCHAR(30) | Current claim processing status |