SQL Exercice – Classify Salary Levels with SQL CASE

Practical SQL exercise using the CASE statement in PostgreSQL to classify employees by salary level. Learn how to create a new column that assigns “High”, “Medium” or “Low” categories according to each employee’s salary range, with clear syntax and tested examples.

Classify Salary Levels with SQL CASE – Practical PostgreSQL Example

🧭 Role: Exercice
🗂️ Area: Data Science
📅 Year: 2025
🧩 Stack: SQL
📝 Credits: deGalaLab

Results / Insights

| full_name | salary | nivell_sou |
| ----------- | ------ | ---------- |
| Pau Solé | 68000 | Alt |
| Jordi Riu | 61000 | Alt |
| Anna Serra | 52000 | Mitjà |
| Marta Vidal | 39000 | Baix |

Create an additional column named salary_level:

Statement

  • If the salary is > 60000 → 'High'
  • Between 40000 and 60000 → 'Medium'
  • If it is < 40000 → 'Low'
Minimalist DeGalaLab-style icon representing manual insertion of JSON-LD code in an SQL post, featuring code and aggregation symbols.

Solution

SELECT 
    full_name,
    salary,
    CASE
        WHEN salary > 60000 THEN 'High'
        WHEN salary BETWEEN 40000 AND 60000 THEN 'Medium'
        ELSE 'Low'
    END AS salary_level
FROM emp
ORDER BY salary DESC;

Extra practice:

  1. Run each query in the Query Tool.
  2. Modify salary values and test again — you’ll see how the averages and levels change.
  3. To save your queries, use File → Save Query (it creates a reusable .sql file).