Bird
0
0

Consider the table Inventory with columns quantity and type. What rows will this query return?

medium📝 query result Q4 of 15
SQL - CASE Expressions
Consider the table Inventory with columns quantity and type. What rows will this query return?

SELECT * FROM Inventory WHERE CASE WHEN type = 'Perishable' THEN quantity < 20 ELSE quantity >= 50 END;
ARows where perishable items have quantity 50 or more, and non-perishable items have quantity less than 20
BRows where all items have quantity less than 20
CRows where all items have quantity 50 or more
DRows where perishable items have quantity less than 20, and non-perishable items have quantity 50 or more
Step-by-Step Solution
Solution:
  1. Step 1: Understand CASE condition

    If type = 'Perishable', filter rows with quantity < 20.
  2. Step 2: Else condition

    For other types, filter rows with quantity >= 50.
  3. Final Answer:

    Rows where perishable items have quantity less than 20, and non-perishable items have quantity 50 or more -> Option D
  4. Quick Check:

    CASE filters based on type and quantity [OK]
Quick Trick: CASE filters differently by type in WHERE [OK]
Common Mistakes:
  • Misinterpreting ELSE condition
  • Assuming all rows must meet one condition
  • Ignoring CASE logic in WHERE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes