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 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.
| Column | Type | Description |
|---|---|---|
| transaction_idPK | BIGINT | Unique transaction identifier |
| merchant_id | INT | Merchant identifier referenced from merchant dimension |
| country_code | VARCHAR(2) | ISO country code where the transaction occurred |
| transaction_ts | TIMESTAMP | Timestamp of the transaction |
| amount_usd | NUMERIC(12,2) | Transaction amount in USD |
| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Merchant identifier |
| merchant_name | VARCHAR(100) | Merchant display name |
| merchant_category | VARCHAR(50) | Merchant category label |