Summary - CASE
- SQL course
- Intermediate
- Lesson 70/115
- 5 min
Write a conditional total report with CASE and SUM.
Summary - CASE
CASE produces conditional expressions. Forms include searched and simple, with ELSE defaults and aggregate use.
SELECT name,
CASE WHEN price > 100 THEN 'pahalı' ELSE 'ucuz' END AS tier
FROM products;Summary CASE query.
name, CASE WHEN price > 100 THEN 'pahalı' ELSE 'ucuz' END … is selected from products.
Practice Summary - CASE
Summary: tag each product with CASE WHEN price > 100 THEN 'pahalı' ELSE 'ucuz' END.
Starter code
-- summary case
SELECT name,
CASE WHEN price > 100 THEN 'pahalı' ELSE 'ucuz'Sample solution
SELECT name,
CASE WHEN price > 100 THEN 'pahalı'
ELSE 'ucuz' END AS tier
FROM products;Expected output
name tier Laptop pahalı Kalem ucuz
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What closes a CASE?
- END Correct answer
- ELSE
- THEN
- WHEN
Explanation: A CASE expression always ends with END.
2 Summary - CASE: match the terms
| Term | Meaning |
|---|---|
CASE WHEN |
condition |
THEN |
result |
ELSE |
default |
END |
close |