Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Transactions by Regional Volume

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

Your question is Rank Transactions by Regional Volume. 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

Write a query using window functions to rank transactions by volume across different regional hubs.

Use the provided hubs and transactions tables. Include only transactions associated with a known hub. Tied transaction volumes must receive the same rank.

Output

  1. One row per included transaction with transaction_id, hub_name, region, volume, and volume_rank.
  2. Rank transactions within each hub by descending volume, with NULL volumes ranked last.
  3. Order by hub_name, volume_rank, then transaction_id.

Schema

hubs
ColumnTypeDescription
hub_idPKINTUnique regional hub identifier
hub_nameVARCHAR(100)Regional hub name
regionVARCHAR(50)Geographic region containing the hub
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
hub_idINTAssociated regional hub identifier
volumeNUMERIC(12,2)Transaction volume used for ranking
Tableshubstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results