Bird
0
0

Given the table Orders with column StatusCode, what will this query return?

medium📝 query result Q4 of 15
SQL - CASE Expressions
Given the table Orders with column StatusCode, what will this query return?
SELECT OrderID, CASE StatusCode WHEN 1 THEN 'Pending' WHEN 2 THEN 'Shipped' ELSE 'Unknown' END AS Status FROM Orders;
AOrderID with status always 'Unknown'
BOrderID with status as '1' or '2' only
COrderID with status as 'Pending' for 1, 'Shipped' for 2, else 'Unknown'
DSyntax error due to missing ELSE
Step-by-Step Solution
Solution:
  1. Step 1: Understand CASE evaluation

    CASE compares StatusCode to 1 or 2, returns matching string.
  2. Step 2: Check ELSE usage

    ELSE returns 'Unknown' if no match; no syntax error.
  3. Final Answer:

    OrderID with status as 'Pending' for 1, 'Shipped' for 2, else 'Unknown' -> Option C
  4. Quick Check:

    CASE maps codes to strings correctly [OK]
Quick Trick: ELSE handles unmatched values in CASE [OK]
Common Mistakes:
  • Assuming ELSE is mandatory
  • Thinking CASE returns numeric codes
  • Expecting syntax error without ELSE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes