RienSQL
TASK #177 · Hard · Klarna

Top-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 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.
Expected columnsregion customer_name total_spent region_rankKlarna
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
customerscustomer_id, name, region
transactionstransaction_id, customer_id, merchant_name, amount, ts