SQL Exercises

PostgreSQL: Intermediate SQL CASE WHEN Exercises

0 Exercises
~0 min

This guide is specifically for PostgreSQL syntax.

Intermediate-level SQL CASE WHEN practice exercises with solutions.

Exercise 1

Question: Categorize employees by salary range (Low, Medium, High).

SELECT name, salary, CASE WHEN salary < 40000 THEN 'Low' WHEN salary BETWEEN 40000 AND 70000 THEN 'Medium' ELSE 'High' END AS salary_category FROM employees;

CASE WHEN provides if-then-else logic in SQL. ELSE handles all unmatched conditions.


PostgreSQL-Specific Notes

This page covers PostgreSQL syntax. Other databases may have different syntax for similar operations.

Related Content

Ready for more practice?

Join SQL Mastery and get access to interactive exercises, quizzes, and more.