Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Transaction Users by Country

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

Your question is Top Transaction Users by Country. 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

FinEdge wants to identify its highest-volume users in each country based on transaction activity. Write a PostgreSQL query to return the top 3 users per country by total transaction volume.

Requirements

  1. Join users and transactions.
  2. Calculate each user's total transaction volume per country using the sum of amount.
  3. Exclude transactions where amount is NULL.
  4. Return the top 3 users within each country using a window function.
  5. Order the final output by country, then rank, then user_id.

Schema

users
ColumnTypeDescription
user_idPKINTUnique identifier for each user
user_nameVARCHAR(100)User display name
countryVARCHAR(50)Country associated with the user
signup_dateDATEDate the user signed up
transactions
ColumnTypeDescription
transaction_idPKINTUnique identifier for each transaction
user_idINTUser who made the transaction
amountDECIMAL(10,2)Transaction amount
transaction_dateDATEDate of the transaction
Tablesuserstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results