Bird
0
0

How would you modify this nested CASE to also label orders with Priority 'Urgent' and Amount NULL as 'Check Amount'?

hard📝 Application Q9 of 15
SQL - CASE Expressions
How would you modify this nested CASE to also label orders with Priority 'Urgent' and Amount NULL as 'Check Amount'?
SELECT OrderID, CASE WHEN Priority = 'Urgent' THEN CASE WHEN Amount > 1000 THEN 'High Priority' ELSE 'Normal Priority' END ELSE 'Low Priority' END AS PriorityLevel FROM Orders;
AAdd ELSE 'Check Amount' at the end of the outer CASE
BAdd a WHEN Amount IS NULL THEN 'Check Amount' inside the inner CASE before other WHENs
CReplace inner CASE with IF(Amount IS NULL, 'Check Amount', 'Normal Priority')
DAdd a separate CASE outside this query to handle NULL amounts
Step-by-Step Solution
Solution:
  1. Step 1: Identify where to check NULL

    Amount NULL check must be inside inner CASE for Priority='Urgent'.
  2. Step 2: Add WHEN Amount IS NULL THEN 'Check Amount'

    Place this condition before other WHENs to catch NULL first.
  3. Final Answer:

    Add a WHEN Amount IS NULL THEN 'Check Amount' inside the inner CASE before other WHENs -> Option B
  4. Quick Check:

    Check NULL early inside nested CASE [OK]
Quick Trick: Check NULL before other conditions inside nested CASE [OK]
Common Mistakes:
  • Adding ELSE outside inner CASE
  • Using IF instead of CASE
  • Handling NULL outside query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes