Write a query to retrieve the total number of employees in each department.
Ask by Ravi Vishwakarma
Updated 03 Jul 2024
To retrieve the total number of employees in each department from an SQL Server table, you can use the
COUNT()function along withGROUP BY. Here's how you can write the query:Output-
In this query:
EmployeeID,EmployeeNumber, etc.).The
GROUP BY Departmentclause groups the results by theDepartmentcolumn, andCOUNT(EmployeeID)counts the number of employees (EmployeeID) in each department. This will give you the total number of employees in each department listed in your table.