Whenever you're ready, walk me through how you'd approach this.
Chubb underwrites commercial property and casualty policies, and the claims team wants a state-by-state view of payout exposure. You are given the schema below and asked to write the SQL query yourself, on the spot, rather than fix an existing one.
CREATE TABLE policies (
policy_id INT PRIMARY KEY,
policyholder_name VARCHAR(120),
policy_type VARCHAR(40),
state CHAR(2),
effective_date DATE,
premium_amount NUMERIC(10,2)
);
CREATE TABLE claims (
claim_id INT PRIMARY KEY,
policy_id INT REFERENCES policies(policy_id),
claim_date DATE,
claim_amount NUMERIC(10,2),
claim_status VARCHAR(20) -- 'Approved', 'Denied', 'Pending'
);
Write a single SQL query that returns, for every state, the total approved-or-pending claim amount paid out over the last 12 months and the number of distinct policyholders who filed one of those claims, restricted to states with at least 5 qualifying claims, sorted by total payout descending. Explain the query you would write and why.