Chapter 9 · Interview Level
41. Assign Customers to Spending Quartiles
Hard40 XPE-Commerce
Divide customers into four equal-sized spending tiers based on their total order spending. Return customer_id, total_spending, and spending_quartile (1 = lowest, 4 = highest). Sort by total_spending descending.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.