I am attempting to compose a failure of forum ranks on the phpBB forum. Forum ranks are based on your postcount: for those who have between 1-9 posts you are level 1 10-24 and you are level 2 and so forth. (The utmost rank is anything above 2000 posts.)

At this time, my forum rank statistics page is simply doing a lot 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 forth.

The queries run inside a couple of seconds, so I am really just curious (for future reference) an easy method to resolve this issue - it feels as though there needs to be one query I'm able to run that'll return results similar to this:

rank_id | count
1       | 5000
2       | 2000
...

I actually do have another table with a report on the ranks and also the minimum quantity of posts needed to accomplish this rank. Unsure if that is necessary or maybe there is a more clever method to write my queries.

I am utilizing a MySQL DB in the event that helps any, but I am much interested in a mix-database answer.

Stick a UNION together.

SELECT COUNT(*) from _users WHERE post_count>=1 AND post_count<10;
UNION
SELECT COUNT(*) from _users WHERE post_count>=10 AND post_count<25;

Alternatively, you could utilize a Situation When You Should stack them and sum the outcomes to have it on a single row.

SELECT
   SUM(CASE WHEN post_count>=1 AND post_count<10 THEN 1 ELSE 0 END) AS Between_1_10
   SUM(CASE WHEN post_count>=10 AND post_count<25 THEN 1 ELSE 0 END) AS Between_10_25
   SUM(CASE WHEN post_count>=25 AND post_count<100 THEN 1 ELSE 0 END) AS Between_25_100
FROM 
   _users

Or a different way to get it done...

SELECT 
     Count(*) 
     , Category
FROM
(
    SELECT
       CASE 
          WHEN post_count>=1 AND post_count<10 THEN '1_To_10'
          WHEN post_count>=10 AND post_count<25 THEN '10_To_25'
          WHEN post_count>=25 AND post_count<100 THEN '25_To_100'
          ELSE 'Over_100' 
       END As Category
    FROM
       _users
) as InnerTable
GROUP BY
   Category

I believe you are searching for SELECT CASE...WHEN.