Questions: CASE WHEN: Conditional Expressions in SQL

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A developer writes: CASE WHEN score >= 70 THEN 'C' WHEN score >= 80 THEN 'B' WHEN score >= 90 THEN 'A' ELSE 'F' END. A student with score 95 receives which grade?

A'A' — the highest matching condition wins
B'C' — the first true condition (95 >= 70) is returned and evaluation stops
C'F' — no condition matches because evaluation happens in reverse order
DNULL — multiple conditions are simultaneously true, producing a conflict
Question 2 Multiple Choice

A query calculates `price * CASE WHEN discount_eligible THEN 0.9 END` with no ELSE clause. For rows where discount_eligible is false, this expression evaluates to:

Aprice * 1.0 — CASE defaults to 1 when no ELSE is provided
Bprice * 0 — CASE returns 0 when no condition matches
CNULL — CASE with no matching branch returns NULL, and NULL in arithmetic produces NULL
DAn error — SQL raises an exception when CASE has no matching branch
Question 3 True / False

A CASE expression evaluates most its WHEN conditions for nearly every row, even after finding the first true condition.

TTrue
FFalse
Question 4 True / False

CASE WHEN can primarily appear in the SELECT list of a query, not inside aggregate functions or ORDER BY clauses.

TTrue
FFalse
Question 5 Short Answer

You need a single query against an orders table that returns three counts in one row: how many orders are 'pending', how many are 'paid', and how many are 'cancelled'. How would you use CASE WHEN to accomplish this?

Think about your answer, then reveal below.