TASK #177 · Hard · KlarnaTop-3 Spenders per Region
Your brief
For every region (customers.region: DE / AT /
CH / SE) find the three customers with the highest purchase
totals.
Write a query that returns region, customer_name, total_spent and region_rank (from 1 to 3). Compute the rank with
Sort the result by region, then by region_rank.
Write a query that returns region, customer_name, total_spent and region_rank (from 1 to 3). Compute the rank with
ROW_NUMBER() using
PARTITION BY region ORDER BY SUM(amount) DESC.
Test data excludes ties between two customers in the same
region.
Sort the result by region, then by region_rank.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
customerscustomer_id, name, regiontransactionstransaction_id, customer_id, merchant_name, amount, ts