Say I have
SELECT *, count(userid) FROM stars GROUP by userid
GROUP by userid
Use two levels of
select cnt, count(*), min(userid), max(userid) from (select userid, count(*) as cnt from stars group by userid ) u group by cnt order by cnt;
I call this type of query a "histogram of histograms" query. I include the
max() values because I often find those useful for further investigation.