I got an error "Common table expression defined but not used." when using CTE in SQL query
This is my SQL Query
With EmployeeCount(DepartmentId, TotalEmployees)
as
(
Select [Department_ID], COUNT(*) as TotalEmployees
from Employee
group by [Department_ID]
)
select GETDATE()
Select Department_Name , TotalEmployees from Department
join EmployeeCount
on Department.ID = EmployeeCount.DepartmentId
order by TotalEmployees