Part 106: The CASE Expression: Simple vs Searched CASE
CASE is SQL's equivalent of if / else or switch statements.
1. Searched CASE (Most Powerful & Flexible)
SELECT
product_name,
stock_quantity,
CASE
WHEN stock_quantity = 0 THEN 'Out of Stock'
WHEN stock_quantity < 10 THEN 'Critical Low'
WHEN stock_quantity < 50 THEN 'Moderate'
ELSE 'Sufficient'
END AS inventory_health
FROM products;
Key Takeaways
- Always provide an
ELSEclause to prevent unhandled conditions from evaluating toNULL.
In Part 107, we explore Conditional Aggregation with CASE Expressions!

