SQL Practice Problem #010

Label orders with CASE

Return each order id and a size label: High for orders of 100 or more, otherwise Standard.

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

idcustomer_idtotal_amountordered_at
101158.52026-03-02
10221042026-03-07

Output

Expected Output

idorder_size
101Standard
102High

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

Related Problems