Bird
0
0

What will this SQL query output?

medium📝 query result Q5 of 15
SQL - CASE Expressions
What will this SQL query output?
SELECT Product, CASE WHEN Stock = 0 THEN 'Out of stock' WHEN Stock < 5 THEN 'Low stock' ELSE 'In stock' END AS Status FROM Inventory;
AProduct names with stock status as 'Out of stock', 'Low stock', or 'In stock'
BOnly products with stock equal to zero
CTotal count of products grouped by stock status
DSyntax error due to multiple WHEN clauses
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple WHEN conditions in CASE

    The CASE checks Stock value and returns different text for zero, less than five, or others.
  2. Step 2: Predict output

    The query lists all products with a Status column showing the correct stock message.
  3. Final Answer:

    Product names with stock status as 'Out of stock', 'Low stock', or 'In stock' -> Option A
  4. Quick Check:

    CASE handles multiple conditions correctly [OK]
Quick Trick: Multiple WHENs let CASE handle many conditions [OK]
Common Mistakes:
  • Thinking multiple WHENs cause syntax errors
  • Assuming CASE filters rows
  • Confusing output with aggregation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes