Bucket customers by spend

Bucket customers by spend

Medium SQL Functions 17 views
Explanation Complexity

Problem Statement

Create spend_bucket as LOW (20000) using CASE on total spend.

Input Format

SQL query

Output Format

Result set

Example

Orders(customer_id, total_amount)
Customer + bucket

Constraints

Use CASE and SUM

Input / Output Format

Input Format
SQL query
Output Format
Result set
Constraints
Use CASE and SUM

Examples

Input:
Orders(customer_id, total_amount)
Output:
Customer + bucket

Example Solution (Public)

SQL
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;

Official Solution Code

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;
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.