0
0
SQLquery~10 mins

Why CASE expressions are needed in SQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return 'Adult' if age is 18 or more, else 'Minor'.

SQL
SELECT name, CASE WHEN age >= [1] THEN 'Adult' ELSE 'Minor' END AS status FROM people;
Drag options to blanks, or click blank then click option'
A18
B21
C16
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong age value like 21 or 16 changes the classification incorrectly.
Forgetting to use '>=' causes wrong results.
2fill in blank
medium

Complete the code to assign 'Pass' if score is 50 or more, otherwise 'Fail'.

SQL
SELECT student, CASE WHEN score >= [1] THEN 'Pass' ELSE 'Fail' END AS result FROM exams;
Drag options to blanks, or click blank then click option'
A40
B50
C60
D70
Attempts:
3 left
💡 Hint
Common Mistakes
Using 40 or 60 changes pass/fail results incorrectly.
Not using '>=' causes wrong classification.
3fill in blank
hard

Fix the error in the CASE expression to categorize salary as 'High' if above 70000, else 'Low'.

SQL
SELECT employee, CASE WHEN salary [1] 70000 THEN 'High' ELSE 'Low' END AS category FROM staff;
Drag options to blanks, or click blank then click option'
A<=
B<
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' reverses the logic.
Using '>=' includes 70000 as 'High' which may not be intended.
4fill in blank
hard

Fill both blanks to classify temperature as 'Cold' if below 15, 'Warm' if between 15 and 25, else 'Hot'.

SQL
SELECT city, CASE WHEN temp < [1] THEN 'Cold' WHEN temp <= [2] THEN 'Warm' ELSE 'Hot' END AS weather FROM forecast;
Drag options to blanks, or click blank then click option'
A15
B20
C25
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing thresholds causes wrong weather classification.
Using wrong comparison operators changes results.
5fill in blank
hard

Fill all three blanks to assign grade: 'A' if score >= 90, 'B' if >= 75, else 'C'.

SQL
SELECT student, CASE WHEN score >= [1] THEN 'A' WHEN score >= [2] THEN 'B' ELSE [3] END AS grade FROM results;
Drag options to blanks, or click blank then click option'
A90
B75
C'C'
D'B'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong thresholds mixes grades.
Not quoting grade letters causes syntax errors.