0
0
SQLquery~10 mins

CASE in SELECT for computed columns in SQL - Interactive Code Practice

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

Complete the code to create a computed column named 'status' that shows 'Adult' if age is 18 or more, otherwise 'Minor'.

SQL
SELECT name, age, CASE WHEN age [1] 18 THEN 'Adult' ELSE 'Minor' END AS status FROM people;
Drag options to blanks, or click blank then click option'
A>=
B<
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>=' causes incorrect classification.
Using '=' only matches exactly 18, missing older ages.
2fill in blank
medium

Complete the code to assign 'High' to scores above 80, otherwise 'Low'.

SQL
SELECT student, score, CASE WHEN score [1] 80 THEN 'High' ELSE 'Low' END AS performance FROM results;
Drag options to blanks, or click blank then click option'
A<=
B>
C=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' includes scores 80 or below as 'High', which is wrong.
Using '=' only matches exactly 80, missing higher scores.
3fill in blank
hard

Fix the error in the CASE statement to correctly label 'Pass' for marks 50 or more, else 'Fail'.

SQL
SELECT student, marks, CASE WHEN marks [1] 50 THEN 'Pass' ELSE 'Fail' END AS result FROM exams;
Drag options to blanks, or click blank then click option'
A<
B>
C>=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' excludes marks exactly 50 from passing.
Using '=' only matches marks exactly 50.
4fill in blank
hard

Fill both blanks to classify salary as 'Low' if less than 3000, 'Medium' if between 3000 and 7000, else 'High'.

SQL
SELECT employee, salary, CASE WHEN salary [1] 3000 THEN 'Low' WHEN salary [2] 7000 THEN 'Medium' ELSE 'High' 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 condition would misclassify salaries.
Using '>' instead of '<=' in the second condition excludes 7000.
5fill in blank
hard

Fill both blanks to classify temperature as 'Cold' below 10, 'Warm' between 10 and 25, and 'Hot' above 25.

SQL
SELECT city, temperature, CASE WHEN temperature [1] 10 THEN 'Cold' WHEN temperature [2] 25 THEN 'Warm' ELSE 'Hot' END AS temp_label FROM weather;
Drag options to blanks, or click blank then click option'
A<
B>=
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<' in the first condition mislabels temperatures.
Using '>' instead of '<=' in the second condition excludes 25.