I'm trying to compose a breakdown of forum ranks on a phpBB forum. Forum ranks are defined by your postcount: if you have between 1-9 posts you're level 1; 10-24 and you're level 2; and so on. (The maximum rank is anything above 2000 posts.)
Right now, my forum rank statistics page is just doing a bunch of dumb queries:
SELECT COUNT(*) from _users WHERE post_count>=1 AND post_count<10;
SELECT COUNT(*) from _users WHERE post_count>=10 AND post_count<25;
... And so on.
The queries run in a few seconds, so I'm really just curious (for future reference) a better way to solve this problem - it feels like there ought to be one query I can run that'll return results akin to this:
rank_id | count
1 | 5000
2 | 2000
...
I do have another table which has a listing of the ranks and the minimum number of posts needed to achieve that rank. Not sure if that's necessary or if there's a more clever way to write my queries.
I'm using a MySQL DB if that helps any, but I'm much more interested in a cross-database answer.