How do you query a database to verify that a policy update correctly cascaded to related claims records?
Write a PostgreSQL query that evaluates the latest applied update for each policy against claims that existed when the update was applied. Treat a claim as compliant only when its policy version and limit match the update.
policy_id, policy_name, update_id, expected_version, expected_limit, related_claim_count, compliant_claim_count, noncompliant_claim_count, and cascade_status.policy_id.| Column | Type | Description |
|---|---|---|
| policy_idPK | INTEGER | Unique policy identifier |
| policy_name | VARCHAR(100) | Display name of the policy |
| policy_type | VARCHAR(40) | Insurance policy category |
| Column | Type | Description |
|---|---|---|
| update_idPK | INTEGER | Unique policy update identifier |
| policy_id | INTEGER | Policy affected by the update |
| new_version | INTEGER | Policy version introduced by the update |
| new_limit | NUMERIC(12,2) | Policy limit introduced by the update |
| update_status | VARCHAR(20) | Lifecycle status of the update |
| applied_at | TIMESTAMPTZ | Timestamp when the update was applied |
| Column | Type | Description |
|---|---|---|
| claim_idPK | INTEGER | Unique claim identifier |
| policy_id | INTEGER | Policy associated with the claim |
| claim_opened_at | TIMESTAMPTZ | Timestamp when the claim was opened |
| policy_version | INTEGER | Policy version stored on the claim |
| policy_limit | NUMERIC(12,2) | Policy limit stored on the claim |
| claim_status | VARCHAR(20) | Current claim status |