Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Total and Customer Ranking

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Running Total and Customer Ranking. Start with the requirements and the two 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.

You need to log in / sign up to run or submit.

Problem

Mutual of Omaha's claims analytics team needs a regional view of paid claim activity. Write a PostgreSQL query that aggregates paid claims per policyholder, calculates a regional running total, and ranks policyholders within each region.

Requirements

  1. Include only claims with claim_status = 'Paid' and policyholders with at least one non-null claim amount.
  2. Calculate each policyholder's total paid claims.
  3. Calculate a running total within each region, ordered by total paid claims descending and policyholder_id ascending as a tie-breaker.
  4. Rank policyholders within each region by total paid claims descending. Tied totals must receive the same rank.

Schema

policyholders
ColumnTypeDescription
policyholder_idPKINTUnique policyholder identifier
policyholder_nameVARCHAR(100)Policyholder name
regionVARCHAR(30)Geographic servicing region
claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
policyholder_idINTReferenced policyholder identifier
claim_dateDATEDate the claim was recorded
claim_amountDECIMAL(12,2)Claim amount
claim_statusVARCHAR(20)Claim processing status
Tablespolicyholdersclaims
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results