Write a SQL query using window functions to calculate a 7-day rolling average of claim costs by claim and flag claims whose cost trend accelerates.
Use the claim_costs table. Treat acceleration as a positive increase in the rolling average that is larger than the preceding increase. Preserve rows with null costs.
claim_id, then cost_date.claim_id, cost_date, daily_cost, rolling_7_day_avg, and acceleration_flag.acceleration_flag must be a Boolean.| Column | Type | Description |
|---|---|---|
| claim_cost_idPK | INT | Unique cost observation identifier |
| claim_id | INT | Claim identifier |
| cost_date | DATE | Date of the claim cost observation |
| daily_cost | DECIMAL(12,2) | Cost recorded for the claim on the observation date |