w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display those departments where any manager is managing 4 or more employees

SQL SORTING and FILTERING on HR Database: Exercise-30 with Solution

30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.

Sample table : employees


Sample Solution:

SELECT DISTINCT department_id
	FROM employees
		GROUP BY department_id, manager_id 
			HAVING COUNT(employee_id) >=4;

Sample Output:

 department_id
---------------
            80
            50
            60
           100
            30
(5 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display those departments where any manager is managing 4 or more employees - Duration

Rows:

Query visualization of Display those departments where any manager is managing 4 or more employees - Rows

Cost:

Query visualization of Display those departments where any manager is managing 4 or more employees - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.
Next: Write a query in SQL to display those departments where more than ten employees work who got a commission percentage.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming