Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Merchants by Country Volume

HardSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Top Merchants by Country Volume. Read through the requirements and the two tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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

Problem

You are given a large Mastercard transaction fact table and a merchant dimension. Write a PostgreSQL query to return the top 5 merchants by transaction volume for each country for the last calendar month. Treat volume as the count of transactions, exclude rows with a null merchant_id, and break ties by higher transaction count first, then lower merchant_id.

Schema

mc_transactions
ColumnTypeDescription
transaction_idPKBIGINTUnique transaction identifier
merchant_idINTMerchant identifier referenced from merchant dimension
country_codeVARCHAR(2)ISO country code where the transaction occurred
transaction_tsTIMESTAMPTimestamp of the transaction
amount_usdNUMERIC(12,2)Transaction amount in USD
mc_merchants
ColumnTypeDescription
merchant_idPKINTMerchant identifier
merchant_nameVARCHAR(100)Merchant display name
merchant_categoryVARCHAR(50)Merchant category label
Tablesmc_transactionsmc_merchants
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results