← All Exercises
SQL HAVING Clause
intermediatesql
Background
HAVING filters groups after GROUP BY aggregation, while WHERE filters individual rows before grouping.
Problem
Write a SQL query to find departments where the total salary expenditure exceeds 500000.
Input
An employees table with id, name, department, salary columns.
Output
Departments with total salary > 500000.
Sample tests
Sample 1
Input: departments with total salaries 400k, 600k, 800k
Expected: 2 departments (600k and 800k)
Your solution
Learning objective
Learn HAVING vs WHERE, aggregate filtering, and the SQL clause execution order.