0
0
MySQLquery~10 mins

CASE WHEN expression in MySQL - Interactive Code Practice

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

Complete the code to select the grade based on score using CASE WHEN.

MySQL
SELECT score, CASE WHEN score >= 90 THEN 'A' ELSE 'F' END AS grade FROM exams WHERE score [1] 80;
Drag options to blanks, or click blank then click option'
A!=
B<
C=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '>=' causes only scores exactly 80 to be selected.
Using '<' selects scores less than 80, which is opposite of the goal.
2fill in blank
medium

Complete the code to assign 'Pass' or 'Fail' based on marks using CASE WHEN.

MySQL
SELECT student_id, marks, CASE WHEN marks [1] 50 THEN 'Pass' ELSE 'Fail' END AS result FROM results;
Drag options to blanks, or click blank then click option'
A>=
B<
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' assigns 'Pass' to marks below 50, which is incorrect.
Using '=' only passes marks exactly 50, missing others.
3fill in blank
hard

Fix the error in the CASE WHEN expression to categorize age groups.

MySQL
SELECT name, age, CASE WHEN age [1] 18 THEN 'Minor' ELSE 'Adult' END AS age_group FROM people;
Drag options to blanks, or click blank then click option'
A<
B=>
C<=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=>' causes syntax error.
Using '==' is not valid in SQL for comparisons.
4fill in blank
hard

Fill both blanks to classify salary levels using CASE WHEN.

MySQL
SELECT employee_id, salary, CASE WHEN salary [1] 50000 THEN 'Low' WHEN salary [2] 100000 THEN 'High' ELSE 'Medium' END AS salary_level FROM employees;
Drag options to blanks, or click blank then click option'
A<
B>=
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' in the first blank would misclassify salaries equal to 50000.
Using '<' in the second blank would misclassify salaries exactly 100000.
5fill in blank
hard

Fill all three blanks to create a CASE WHEN expression that labels product stock status.

MySQL
SELECT product_name, stock, CASE WHEN stock [1] 0 THEN 'Out of stock' WHEN stock [2] 50 THEN 'Low stock' ELSE 'In stock' END AS stock_status FROM inventory WHERE stock [3] 0;
Drag options to blanks, or click blank then click option'
A=
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' in second blank excludes stock exactly 50.
Using '!=' instead of '=' in first blank misclassifies zero stock.
Using '<' instead of '>=' in third blank excludes zero stock.