Loading lesson path
expression is used to define different results based on specified conditions in an SQL statement.
expression goes through the conditions and stops at the first match (like an if-then-else statement). So, once a condition is true, it will stop processing and return the result. If no conditions are true, it returns the value in the ELSEclause. If there is no
clause and no conditions are true, it returns NULL.
condition1
result1
condition2
result2
conditionN
resultN
default_result
END;expression to categorize data (Price) and we create a new column (PriceCategory) that shows in which price category each product is:
SELECT ProductName, Price,
Formula
WHEN Price < 20 THEN 'Low Cost'
WHEN Price BETWEEN 20 AND 50 THEN 'Medium Cost'FROM Products;