0
0
MySQLquery~10 mins

IF function 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 use the IF function to check if the score is greater than 50.

MySQL
SELECT IF(score [1] 50, 'Pass', 'Fail') 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 '=' instead of '>' causes the condition to check equality, not greater than.
Using '<' reverses the logic and gives wrong results.
2fill in blank
medium

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

MySQL
SELECT IF(age [1] 18, 'Adult', 'Minor') 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 '>' excludes exactly 18 years old.
Using '<=' reverses the logic.
3fill in blank
hard

Fix the error in the IF function to correctly check if salary is not equal to 0.

MySQL
SELECT IF(salary [1] 0, 'Has Salary', 'No Salary') FROM employees;
Drag options to blanks, or click blank then click option'
A=
B>
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' checks for equality, which is the opposite of what is needed.
Using '>' or '<' changes the logic incorrectly.
4fill in blank
hard

Fill both blanks to return 'High' if price is greater than 100, else 'Low'.

MySQL
SELECT IF(price [1] 100, '[2]', 'Low') AS price_level FROM products;
Drag options to blanks, or click blank then click option'
A>
B<
CHigh
DMedium
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' reverses the condition.
Returning 'Medium' instead of 'High' changes the expected output.
5fill in blank
hard

Fill both blanks to return the uppercase name if active is 1 and age is over 30, else return 'Inactive'.

MySQL
SELECT IF(active = 1 AND age [1] 30, UPPER(name), '[2]') AS status_name FROM users;
Drag options to blanks, or click blank then click option'
A>
B)
CInactive
D(
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses in UPPER function causes syntax errors.
Using '<' instead of '>' reverses the condition.
Returning wrong string instead of 'Inactive'.