Use HAVING for group filter
SQL
Easy
4 views
Problem Description
From Employees and Departments, show only those departments where employee count is more than 5. Display dept_name and the count.
Sample Test Case
Input:
Employees(dept_id), Departments(dept_id, dept_name)
Constraints
Think: HAVING is for filtering groups, not rows
Official Solution
SELECT d.dept_name, COUNT(*) AS emp_count FROM Employees e JOIN Departments d ON d.dept_id = e.dept_id GROUP BY d.dept_name HAVING COUNT(*) > 5;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!