Read first
Task 18
CASE WHEN
CASE labels each row with your own logic.
Task
CASE WHEN is useful for…
The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.
What you start with
SELECT name, CASE WHEN city = 'Faisalabad' THEN 'local' ELSE 'other' END AS area FROM students;
Syntax reference
SELECT name, CASE WHEN city = 'Faisalabad' THEN 'local' ELSE 'other' END AS area FROM students;
Read it, then write it yourself. Copy-paste teaches nothing.
The sample database
CREATE TABLE courses (id INTEGER PRIMARY KEY, title TEXT, monthly_fee INTEGER); CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT, city TEXT, course_id INTEGER, joined TEXT); CREATE TABLE fees (id INTEGER PRIMARY KEY, student_id INTEGER, month TEXT, amount INTEGER, paid INTEGER); INSERT INTO courses VALUES (1,'Web Design',9000),(2,'Python',11667),(3,'JavaScript',11667),(4,'AI & Prompt Engineering',15000); INSERT INTO students VALUES (1,'Sara','Faisalabad',2,'2026-01-12'), (2,'Ali','Faisalabad',1,'2026-01-20'), (3,'Hina','Jhumra',2,'2026-02-02'), (4,'Bilal','Faisalabad',4,'2026-02-15'), (5,'Ayesha','Sargodha',3,'2026-03-01'), (6,'Usman','Jhumra',1,'2026-03-11'), (7,'Zainab','Faisalabad',4,'2026-04-05'), (8,'Hamza','Faisalabad',3,'2026-04-19'); INSERT INTO fees VALUES (1,1,'2026-01',11667,1),(2,1,'2026-02',11667,1), (3,2,'2026-01',9000,1),(4,2,'2026-02',9000,0), (5,3,'2026-02',11667,1),(6,3,'2026-03',11667,0), (7,4,'2026-02',15000,1),(8,4,'2026-03',15000,1), (9,5,'2026-03',11667,0), (10,6,'2026-03',9000,1),(11,6,'2026-04',9000,0), (12,7,'2026-04',15000,0), (13,8,'2026-04',11667,1);
SQL
1 automatic check Section 2 · Summaries
Code editor
Ctrl + Enter runs
Run your code to see the output and the checks.
Your result
Submit your code to see results
Write your code in the middle column and press Run code.
Next task (pass every check first)
Hint
Ask yourself: CASE WHEN is useful for…
Still stuck? Open “Syntax reference” in the left column, then type it yourself and change one value.