Skip to content
Advertisement

Find the number of employees working under a manager

I have three tables called branch,employee and manager structured like this

I want to view the id of each manager and the count of the employees he has under his supervision like this

I have made this so far that shows which branch each manager works on but i don’t know how to proceed with the counting.

The solution i have in mind is first find in which branch each manager is working and then count all the employees of that branch minus one ( the manager). The problem is i don’t know how to exactly express it in sql.

Advertisement

Answer

Since each branch can only have one manager, you can count the number of employees in a branch and then join the manager to their branch. From there you can count the number of employees in each branch.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement