如何编写SQL查询以按员工数量的降序列出部门名称?
答案 0 :(得分:0)
如果是不同的表,则可以将相关子查询放在ORDER BY
部分中。或者您可以加入表格,然后将它们分组,然后order by count DESC
。
其次是性能更好
答案 1 :(得分:0)
你可以试试这个
SELECT Department.DeptName, COUNT(Employee.FName) AS EmpCount
FROM Employee INNER JOIN
Department ON Employee.DeptId = Department.ID
GROUP BY Department.DeptName
order by EmpCount