Home > front end >  How do i sort the "DeptNumberCount" from largest to lowest?
How do i sort the "DeptNumberCount" from largest to lowest?

Time:02-05

SELECT DeptName , COUNT(*) AS "DeptNumberCount"
FROM Department
GROUP BY DeptName

This is the code i'm running that im working on for SQL but i'm trying to get the count to show up first then the deptname, but it doesn't allow me to and i need to have it so it's largest to smallest.

Can someone please help

I've tried putting:

GROUP BY "DeptNumberCount" , DeptName or 
GROUP BY DeptNumberCount , DeptName

And the HAVING clause is giving me a syntax

CodePudding user response:

Try ordering descending by the department count:

SELECT COUNT(*) AS "DeptNumberCount", DeptName
FROM Department
GROUP BY DeptName
ORDER BY COUNT(*) DESC;
  • Related