Problem
Task
Return each order id and a size label: High for orders of 100 or more, otherwise Standard.
Schema
Table Schema
orders(id, customer_id, total_amount, ordered_at)
Input
Sample Data
| id | customer_id | total_amount | ordered_at |
|---|---|---|---|
| 101 | 1 | 58.5 | 2026-03-02 |
| 102 | 2 | 104 | 2026-03-07 |
Output
Expected Output
| id | order_size |
|---|---|
| 101 | Standard |
| 102 | High |
Answer
Check Your Solution
Show Answer and Explanation
Correct Answer
SELECT id,
CASE
WHEN total_amount >= 100 THEN 'High'
ELSE 'Standard'
END AS order_size
FROM orders;
Explanation
CASE creates a derived value based on conditions. The WHEN branch handles orders of 100 or more, and ELSE handles every remaining order.
Common Mistakes
- Forgetting END before the alias.
- Using double quotes for string values in a MySQL setup where single quotes are expected.
- Leaving out ELSE and returning NULL for standard orders.
Concepts
Related Concepts
CASE
Conditional Expressions
Aliases
SELECT
Derived Column
Next practice