Skip to content
Justice Tech School

CASE for Labels

CASE returns different values by condition, like if else.

Example
SELECT name,
  CASE WHEN score >= 85 THEN 'A' WHEN score >= 70 THEN 'B' ELSE 'C' END AS grade
FROM students
WHERE score IS NOT NULL;

Result

name    | grade
Ada     | A
Kofi    | B
Amina   | A
Wanjiru | C
Tunde   | B
Zainab  | A
Sipho   | C

Exercise

Close a CASE.

CASE WHEN a THEN 1 ELSE 0 

Quiz Test

How does CASE finish?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.