Skip to content

THEN

SELECT
CASE
WHEN price > 200 THEN 'Expensive'
ELSE 'Cheap'
END AS Price_Category
FROM
Products
+----------------+
| Price_Category |
+----------------+
| Expensive |
| Cheap |
| Expensive |
| Cheap |
+----------------+

The CASE statement is used to perform conditions in SQL. The THEN keyword acts as the outcome when the condition in the WHEN clause is met. In the given code, the CASE statement checks the price column, if the price is greater than 200 it displays ‘Expensive’, otherwise it displays ‘Cheap’. The result is a new column named Price_Category with the price categories.