SQL COUNT() with GROUP BY - Excellent Resource

I needed an SQL query with a GROUP BY and an SQL SELECT COUNT(*) in but I couldn't get it to work. The idea was to see how many rows would be in the table, but with the 'GROUP BY' I was getting lots of 1's (I ended up just running the query without a limit to get the full 50'000+ row table). Whilst I was looking around I came across this resource:
https://www.w3resource.com/sql/aggregate-functions/count-with-group-by.php

And in the comments:

SELECT working_area, COUNT(*)
FROM agents
GROUP BY working_area
HAVING COUNT( * ) > 1
ORDER BY 2 DESC;

Absolutely fantastic bit of SQL.

Image: Excellent Pictorial Representation of SQL COUNT() and GROUP BY

Comments