Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Clients by Premium

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

Your question is Rank Clients by Premium. 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.

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

Problem

Arthur J. Gallagher & needs a regional view of client premium performance. Write a PostgreSQL query that ranks clients by their total active policy premium within each assigned region.

Requirements

  1. Aggregate active policy premiums for each client, treating missing or NULL premium values as zero.
  2. Include clients with no active policies, assigning them a total premium of zero.
  3. Use RANK() partitioned by region, with the highest total premium receiving rank 1. Preserve ties by assigning the same rank.
  4. Return the region, client, total active premium, and rank, ordered by region, rank, and client name.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique region identifier
region_nameVARCHAR(80)Operating region name
clients
ColumnTypeDescription
client_idPKINTUnique client identifier
client_nameVARCHAR(120)Client legal or trading name
region_idINTAssigned region identifier
policies
ColumnTypeDescription
policy_idPKINTUnique policy identifier
client_idINTClient that owns the policy
policy_numberVARCHAR(30)Policy reference number
policy_statusVARCHAR(20)Policy lifecycle status
premium_amountNUMERIC(12,2)Policy premium amount
Tablesregionsclientspolicies
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results