Aggregate Queries: Finding accounts with large numbers of cases

Since I’ve have multiple people ask about how to find <type of object> with over <number> child records many time in many different job roles I wanted to throw together a quick blog post about this.
<div>
</div><div>For the sake of this example, let’s say we want to find out most “needy” customers, looking for ones that have created over 80 cases this year.</div><div>
</div><div>This is as simple as running the query:</div>

SELECT AccountId, COUNT(Id) FROM Case WHERE CreatedDate = THIS_YEAR GROUP BY AccountId HAVING Count(Id) > 80

which gives us a nice simple set of results to work with:</div> </div>