CASE WHEN: Bucket Customer Spend Into Tiers

Basics
BasicsCASE WHENConditionalGoogleAmazonMeta

Table

  • customers(user_id INT, spend INT)

Task

From customers(user_id, spend), classify each user into tier: 'Low' (spend < 50), 'Medium' (50 <= spend < 200), or 'High' (spend >= 200). Return user_id, tier ordered by user_id ASC.

Why It Matters: CASE WHEN creates custom business segments (spend tiers, risk bands, SLA buckets) directly inside SQL queries.

Output columns: user_id, tier

Example

Input — customers

user_idspend
120
250
3199
4200

Expected Output

user_idtier
1Low
2Medium
3Medium
4High

Explanation: Evaluates each customer's spend against the tier thresholds in order and assigns the matching label.

Requirements

  • Exact output columns: user_id, tier
  • Row order: Exact ORDER BY order is checked by the grader.
  • Query type: Write a single read-only Standard SQL SELECT (or WITH ... SELECT) query.

Constraints & Evaluation Criteria

  • Return `user_id, tier` ordered by `user_id ASC`.

Hints

SQL
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
customers (4 rows)
Expected Output / Criteria
4 row(s): (1, Low); (2, Medium); (3, Medium); ...