← SQL Deep Dive
8 / 25
Lesson 8 — CASE labeling
CASE: if / else inside SQL
CASE WHEN condition THEN value ... ELSE value END works like if / elif / else and produces a new column. Conditions are checked top to bottom; the first true one wins.
CASE WHEN temp >= 30 THEN 'hot'
WHEN temp >= 15 THEN 'mild'
ELSE 'cold' END
Why it matters: labelling rows ("VIP", "at risk", "new") directly in the query keeps reports readable without extra code.
Want it another way?
Task
Write the missing WHEN line for 'B' (score 75 or more). Expected labels: A, B, C, B.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.