0
0
SQLquery~10 mins

CASE in WHERE clause 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 filter rows where the status is 'active'.

SQL
SELECT * FROM users WHERE status = [1];
Drag options to blanks, or click blank then click option'
A'inactive'
B'active'
Cactive
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around string literals.
Using a number instead of a string.
2fill in blank
medium

Complete the code to use CASE in WHERE clause to filter users by role.

SQL
SELECT * FROM users WHERE role = CASE WHEN is_admin = 1 THEN [1] ELSE 'user' END;
Drag options to blanks, or click blank then click option'
A'admin'
Badmin
C'guest'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around 'admin'.
Using a number instead of a string.
3fill in blank
hard

Fix the error in the CASE expression inside the WHERE clause.

SQL
SELECT * FROM orders WHERE CASE [1] WHEN 'shipped' THEN 1 ELSE 0 END = 1;
Drag options to blanks, or click blank then click option'
Astatus
Border_date
C1
D'shipped'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal instead of a column in CASE.
Putting quotes around the column name.
4fill in blank
hard

Fill both blanks to filter products by price range using CASE in WHERE clause.

SQL
SELECT * FROM products WHERE price [1] CASE WHEN category = 'luxury' THEN 1000 ELSE [2] END;
Drag options to blanks, or click blank then click option'
A>
B<
C500
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Confusing the price values for categories.
5fill in blank
hard

Fill all three blanks to filter employees by department and salary using CASE in WHERE clause.

SQL
SELECT * FROM employees WHERE salary [1] CASE WHEN department = [2] THEN [3] ELSE 50000 END;
Drag options to blanks, or click blank then click option'
A'HR'
B>
C60000
D'Sales'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around department names.
Using wrong comparison operator for salary.