Write a stored procedure that returns the total number of employees in each department from a given table of employee data.
Given a table of employee data, write a stored procedure that returns the total number of employees in each department.
| Department |
| Sales |
| Marketing |
| IT |
| Department | Total Employees |
| Sales | 10 |
| Marketing | 5 |
| IT | 3 |
SELECT Department, COUNT(*) AS TotalEmployees
GROUP BY Department
This solution is optimal because it uses the GROUP BY clause to group the employees by department, and then uses the COUNT() function to count the number of employees in each department.
This solution is correct and demonstrates a good understanding of SQL.
Evaluated at: 2022-11-26 12:15:42