Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Spending Clients Per Region

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

Your question is Top Spending Clients Per Region. 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

Business Context

American Express Global Business Travel uses Neo reporting to compare corporate travel spend across regional portfolios. The reporting team needs the highest-spending clients for the most recently completed fiscal year.

Task

Write a PostgreSQL query that returns the top three corporate clients by total travel spend within each region for fiscal year 2025, defined as July 1, 2024 through June 30, 2025.

Requirements

  1. Join regions, corporate clients, and travel transactions.
  2. Include clients with no qualifying transactions as zero spend, but exclude clients without an assigned region.
  3. Aggregate transaction amounts by region and client, rank clients within each region, and return ranks 1 through 3.
  4. Order the output by region ID, rank, and client name. Treat NULL transaction amounts as zero and use client name as the deterministic tie-breaker.

Schema

regions
ColumnTypeDescription
region_idPKINTEGERUnique regional portfolio identifier
region_nameVARCHAR(50)Name of the geographic region
corporate_clients
ColumnTypeDescription
client_idPKINTEGERUnique corporate client identifier
client_nameVARCHAR(100)Corporate client name
region_idINTEGERAssigned region identifier
travel_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique travel transaction identifier
client_idINTEGERCorporate client associated with the transaction
transaction_dateDATEDate on which the transaction occurred
amountNUMERIC(12,2)Travel spend amount in dollars
Tablesregionscorporate_clientstravel_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results