Skip to content
Advertisement

How to display number of employees of each position in each department

I have two tables, named Employee and Department.

Employee (Emp_ID, Name, Position, DeptID)

Department (Department_ID, Dept_Name).

The position of an employee may be tech_support, data_entry, or assistant manager.

I want to display the name of each department along with the number of employees working in each position such that each position displayed in a separate column.

If the dept has no employees working in a position, the number displayed shall be zero.

Sample output:

Advertisement

Answer

With a LEFT JOIN of department to employee and conditional aggregation:

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