Bird
0
0

Which query correctly assigns 'Cheap' for prices below 50, 'Affordable' for prices between 50 and 150, and 'Expensive' for prices above 150?

hard📝 Application Q15 of 15
SQL - CASE Expressions
You want to classify products by price range using searched CASE. Which query correctly assigns 'Cheap' for prices below 50, 'Affordable' for prices between 50 and 150, and 'Expensive' for prices above 150?
ASELECT ProductName, CASE WHEN Price < 50 THEN 'Cheap' WHEN Price BETWEEN 50 AND 150 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products;
BSELECT ProductName, CASE WHEN Price > 150 THEN 'Cheap' WHEN Price BETWEEN 50 AND 150 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products;
CSELECT ProductName, CASE WHEN Price < 50 THEN 'Cheap' WHEN Price > 150 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products;
DSELECT ProductName, CASE WHEN Price BETWEEN 50 AND 150 THEN 'Cheap' WHEN Price < 50 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products;
Step-by-Step Solution
Solution:
  1. Step 1: Match conditions to price ranges

    Price < 50 should be 'Cheap', 50 to 150 'Affordable', above 150 'Expensive'.
  2. Step 2: Verify each option's logic

    SELECT ProductName, CASE WHEN Price < 50 THEN 'Cheap' WHEN Price BETWEEN 50 AND 150 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products; correctly orders conditions and labels prices as required. Others mislabel or misorder conditions.
  3. Final Answer:

    SELECT ProductName, CASE WHEN Price < 50 THEN 'Cheap' WHEN Price BETWEEN 50 AND 150 THEN 'Affordable' ELSE 'Expensive' END AS PriceRange FROM Products; -> Option A
  4. Quick Check:

    Conditions match price ranges correctly [OK]
Quick Trick: Order CASE conditions from smallest to largest range [OK]
Common Mistakes:
  • Mixing condition order causing wrong labels
  • Using wrong comparison operators
  • Misplacing BETWEEN ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes