Bird
0
0

You want to categorize sales amounts into 'Low', 'Medium', and 'High' using Simple CASE. Which query correctly assigns:

hard📝 Application Q15 of 15
SQL - CASE Expressions
You want to categorize sales amounts into 'Low', 'Medium', and 'High' using Simple CASE. Which query correctly assigns:
- 'Low' for 0
- 'Medium' for 1
- 'High' for 2 or more (default)?
SELECT SaleID,
CASE SaleAmount
WHEN 0 THEN 'Low'
WHEN 1 THEN 'Medium'
ELSE 'High'
END AS SaleCategory
FROM Sales;
AFails because ELSE cannot be used for multiple values.
BIncorrect because Simple CASE cannot handle ranges like 2 or more.
CCorrectly categorizes sales as described.
DSyntax error due to missing WHEN for 2.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Simple CASE limitations

    Simple CASE matches exact values; ELSE handles all other cases.
  2. Step 2: Analyze the query logic

    WHEN 0 returns 'Low', WHEN 1 returns 'Medium', ELSE covers 2 or more as 'High'.
  3. Final Answer:

    Correctly categorizes sales as described. -> Option C
  4. Quick Check:

    ELSE covers all unmatched values [OK]
Quick Trick: Use ELSE for all other values in Simple CASE [OK]
Common Mistakes:
  • Thinking ELSE can't cover multiple values
  • Trying to use ranges in Simple CASE
  • Expecting WHEN for every possible value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes