Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Clients by Volume per Region

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

Your question is Top Clients by Volume 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

You’re a data engineer at a fintech payments processor that settles card and ACH payments for tens of thousands of SMB and mid-market clients across multiple geographic regions. The revenue team runs quarterly business reviews (QBRs) and wants to identify the most important clients in each region by transaction volume (count of transactions) in the most recently completed calendar quarter. This output feeds an executive dashboard and also triggers account-management workflows, so accuracy around quarter boundaries and tie-handling matters.

Task

Write a SQL query to return the top 3 clients by transaction volume for each region in the last completed quarter.

Requirements

  1. Consider only transactions with status = 'SETTLED'.
  2. Define last quarter as the most recently completed calendar quarter relative to CURRENT_DATE (e.g., if today is 2026-02-13, last quarter is 2025 Q4: 2025-10-01 through 2025-12-31).
  3. Compute transaction volume as COUNT(*) of settled transactions per (region, client_id) in that quarter.
  4. Return exactly 3 rows per region when possible. If a region has fewer than 3 clients with settled transactions in the quarter, return all of them.
  5. Break ties deterministically by ordering by txn_count DESC, then total_amount_usd DESC, then client_id ASC.
  6. Output columns: region, client_id, client_name, txn_count, total_amount_usd, rank_in_region.

Schema

regions
ColumnTypeDescription
region_idPKINTPrimary key
regionVARCHAR(50)Region name (e.g., 'NA', 'EMEA')
clients
ColumnTypeDescription
client_idPKINTPrimary key
client_nameVARCHAR(255)Legal/business name
region_idINTForeign key to regions.region_id
onboarded_atDATEDate client started processing
transactions
ColumnTypeDescription
transaction_idPKBIGINTPrimary key
client_idINTForeign key to clients.client_id
created_atTIMESTAMPTransaction creation timestamp
amount_usdDECIMAL(12,2)Amount in USD
statusVARCHAR(20)Transaction status (e.g., SETTLED, DECLINED)
Tablesregionsclientstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results