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. From the following table, write a SQL query to find those departments where a manager can manage four or more employees. Return department_id.
Sample table : employees
SELECT DISTINCT department_id FROM employees GROUP BY department_id, manager_id HAVING COUNT(employee_id) >=4;
department_id --------------- 80 50 60 100 30 (5 rows)
Relational Algebra Expression:
Relational Algebra Tree:
Contribute your code and comments through Disqus.
Previous: From the following table, write a SQL query to calculate average salary of those employees for each department who get a commission percentage. Return department id, average salary.
Next: From the following table, write a SQL query to find those departments where more than ten employees work, who got a commission percentage. Return department id.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
MySQL export schema without data
mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework