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_id | spend |
|---|---|
| 1 | 20 |
| 2 | 50 |
| 3 | 199 |
| 4 | 200 |
Expected Output
| user_id | tier |
|---|---|
| 1 | Low |
| 2 | Medium |
| 3 | Medium |
| 4 | High |
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 BYorder is checked by the grader. - Query type: Write a single read-only Standard SQL
SELECT(orWITH ... SELECT) query.
Constraints & Evaluation Criteria
- Return `user_id, tier` ordered by `user_id ASC`.
Hints
SQL⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
customers (4 rows)
Expected Output / Criteria
4 row(s): (1, Low); (2, Medium); (3, Medium); ...