PostgreSQL
PostgreSQL CASE
Return different values based on conditions.
Use CASE
SELECT name, year,
CASE
WHEN year >= 2025 THEN 'New'
WHEN year >= 2020 THEN 'Recent'
ELSE 'Older'
END AS age_group
FROM products;PostgreSQL tests WHEN conditions in order and returns the first matching result. ELSE handles rows that match no condition.