Your question is Rolling Claims and Loss Ratio Ranking. Start with the requirements and the three tables 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.
Write a SQL query using window functions to calculate a rolling 30-day claims count by policyholder and rank regions by loss ratio. Use the policy, policyholder, and claims data, treating the 30-day period as the claim date plus the preceding 29 calendar days. Assume loss ratio equals total claim amount divided by total annual premium.
policyholder_name, claim_date, rolling_30_day_claims, region, loss_ratio, and region_rank.| Column | Type | Description |
|---|---|---|
| policyholder_idPK | INT | Unique policyholder identifier |
| policyholder_name | VARCHAR(100) | Policyholder name |
| region | VARCHAR(50) | Policyholder region |
| Column | Type | Description |
|---|---|---|
| policy_idPK | INT | Unique policy identifier |
| policyholder_id | INT | Owning policyholder |
| annual_premium | NUMERIC(12,2) | Annual premium amount |
| Column | Type | Description |
|---|---|---|
| claim_idPK | INT | Unique claim identifier |
| policy_id | INT | Policy associated with the claim |
| claim_date | DATE | Date the claim was recorded |
| claim_amount | NUMERIC(12,2) | Claim loss amount |