how many employees in department MySQL query

Get the department name and number of employees in the department

SELECT department_name AS 'Department Name', 
COUNT(*) AS 'No of Employees' 
FROM departments 
INNER JOIN employees 
ON employees.department_id = departments.department_id 
GROUP BY departments.department_id, department_name 
ORDER BY department_name;
Department Name		No of Employees
Accounting			2
Administration			1
Executive			3
Finance				6
Human Resources			1
IT				5
Marketing			2
Public Relations		1
Purchasing			6
Sales				34
Shipping			45


Leave a Reply