Lesson 15 of 30
CASE: answers that depend
Today at the studio
The HR report must say "junior", "mid" or "senior", not a bare number. The merch report needs a "bestseller" tag. You discover that SQL can make small decisions too.
The idea
CASE turns conditions into values. It checks each WHEN from top to bottom and returns the THEN value of the first one that is true. ELSE covers the rest, and END closes it.
There is a short form for one column: CASE status WHEN 'airing' THEN ... END. A CASE is a normal column, so you can give it a name with AS.
Example
SELECT name, CASE WHEN floor = 1 THEN 'ground' ELSE 'upstairs' END AS where_is_it FROM departments
Your turn
0 of 4 questions
Question 1 of 4
Label each person: senior if the salary is 70000 or more, mid if it is 50000 or more, otherwise junior. Show name and the label.