Recall & Review
beginner
What is the purpose of the
CASE WHEN expression in SQL?The
CASE WHEN expression lets you perform conditional logic inside SQL queries. It works like an if-else statement to return different values based on conditions.Click to reveal answer
beginner
Write the basic syntax of a
CASE WHEN expression.The syntax is:<br>
CASE<br> WHEN condition1 THEN result1<br> WHEN condition2 THEN result2<br> ELSE default_result<br>END
Click to reveal answer
beginner
Can
CASE WHEN be used in the SELECT clause? Give an example.Yes, it can. For example:<br>
SELECT name,<br> CASE WHEN score >= 60 THEN 'Pass'<br> ELSE 'Fail'<br> END AS result<br>FROM students;
Click to reveal answer
intermediate
What happens if none of the
WHEN conditions are true and there is no ELSE clause?If no
WHEN condition matches and there is no ELSE, the CASE expression returns NULL.Click to reveal answer
intermediate
How can
CASE WHEN improve readability compared to nested IF statements?CASE WHEN organizes multiple conditions clearly in one block, making queries easier to read and maintain than many nested IF functions.Click to reveal answer
What does the
CASE WHEN expression return if a condition is true?✗ Incorrect
When a
WHEN condition is true, CASE returns the value after THEN.Which clause is optional in a
CASE WHEN expression?✗ Incorrect
The
ELSE clause is optional. If omitted and no conditions match, CASE returns NULL.Where can you use
CASE WHEN in a SQL query?✗ Incorrect
CASE WHEN can be used in many parts of a query like SELECT, WHERE, ORDER BY, etc.What is the correct way to end a
CASE WHEN expression?✗ Incorrect
Every
CASE expression must end with the keyword END.If you want to assign grades based on scores using
CASE WHEN, which is a valid condition?✗ Incorrect
Conditions in
WHEN must be logical expressions like score > 90.Explain how the
CASE WHEN expression works in SQL and give a simple example.Think of it like an if-else chain inside a query.
You got /5 concepts.
Describe a situation where using
CASE WHEN improves a SQL query compared to multiple separate queries.Consider grading students or categorizing data in one query.
You got /4 concepts.