Challenge - 5 Problems
Simple CASE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of Simple CASE with numeric grades
Given the table Grades with a column
score containing numeric values, what is the output of this query?SELECT score, CASE score WHEN 90 THEN 'A' WHEN 80 THEN 'B' ELSE 'F' END AS grade FROM Grades;
SQL
CREATE TABLE Grades(score INT); INSERT INTO Grades VALUES (90), (80), (70);
Attempts:
2 left
💡 Hint
Simple CASE compares the expression to each WHEN value exactly.
✗ Incorrect
The CASE expression compares the score to each WHEN value. 90 matches 'A', 80 matches 'B', and 70 matches none, so ELSE 'F' applies.
🧠 Conceptual
intermediate1:30remaining
Understanding Simple CASE vs Searched CASE
Which statement correctly describes the difference between Simple CASE and Searched CASE expressions in SQL?
Attempts:
2 left
💡 Hint
Think about how the CASE expression compares or evaluates conditions.
✗ Incorrect
Simple CASE compares one expression to multiple values. Searched CASE evaluates independent conditions in WHEN clauses.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Simple CASE query
Which option contains a syntax error in the Simple CASE expression?
SQL
SELECT id, CASE WHEN status = 'active' THEN 'A' WHEN status = 'inactive' THEN 'I' ELSE 'U' END AS state FROM Users;
Attempts:
2 left
💡 Hint
Check the FROM clause syntax carefully.
✗ Incorrect
Option A is missing the FROM keyword before the table name, causing a syntax error.
❓ optimization
advanced2:30remaining
Optimizing Simple CASE for performance
You have a large table with a column
category containing values 'A', 'B', 'C', or others. Which Simple CASE query is most efficient to categorize rows as 'Group1' for 'A' and 'B', 'Group2' for 'C', and 'Other' otherwise?Attempts:
2 left
💡 Hint
Simple CASE compares one expression to values; using multiple WHENs for same output is valid.
✗ Incorrect
Option B uses Simple CASE correctly with multiple WHENs for 'Group1'. Option B uses Searched CASE, which may be less efficient. Options C and D misclassify or omit 'B'.
🔧 Debug
expert3:00remaining
Debugging unexpected output in Simple CASE
Given this query:
Why might rows with
SELECT id, CASE status WHEN 'active' THEN 'Active' WHEN 'inactive' THEN 'Inactive' ELSE 'Unknown' END AS state FROM Users;
Why might rows with
status = NULL show 'Unknown' instead of NULL?Attempts:
2 left
💡 Hint
Think about how NULL behaves in comparisons.
✗ Incorrect
NULL is not equal to any value, so Simple CASE never matches WHEN clauses for NULL, resulting in ELSE output.