Bucket customers by spend
SQL
Medium
3 views
Problem Description
Create spend_bucket as LOW (20000) using CASE on total spend.
Sample Test Case
Input:
Orders(customer_id, total_amount)
Output:
Customer + bucket
Constraints
Use CASE and SUM
Official Solution
SELECT customer_id, CASE WHEN SUM(total_amount) < 5000 THEN 'LOW' WHEN SUM(total_amount) <= 20000 THEN 'MID' ELSE 'HIGH' END AS spend_bucket FROM Orders GROUP BY customer_id;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!