w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the manager ID and number of employees managed by the manager

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

26. Write a query in SQL to display the manager ID and number of employees managed by the manager.

Sample table: employees


Sample Solution:

SELECT manager_id, COUNT(*) 
	FROM employees 
		GROUP BY manager_id;

Sample Output:

 manager_id | count
------------+-------
        205 |     1
        122 |     8
        120 |     8
        101 |     5
        103 |     4
        108 |     5
        145 |     6
        100 |    14
        201 |     1
        124 |     8
        114 |     5
        121 |     8
        123 |     8
        102 |     1
        146 |     6
        147 |     6
        148 |     6
        149 |     6
          0 |     1
(19 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the manager ID and number of employees managed by the manager - Duration

Rows:

Query visualization of Display the manager ID and number of employees managed by the manager - Rows

Cost:

Query visualization of Display the manager ID and number of employees managed by the manager - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the country ID and number of cities in that country we have.
Next: Write a query in SQL to display the details of jobs in descending sequence on job title.

What is the difficulty level of this exercise?



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