How I would I break a total count query into intervals? For example, if I did a normal count query like:

select status, count(*)
from customers
group by status


and get the result

status   count
-----------------
open     1200
closed   1002


but I want the count to be split into intervals of 500 so I would get a result returned like this

status   count
----------------
open     500
open     500
open     200
closed   500
closed   500
closed   2
You could potentially do this using ROW_NUMBER.

I'd just advise to steer away from this whole thing, as it's not particularly useful....

If you were to do this, make sure you replace the &lt;some_id&gt; with the Customer ID or similar...

SELECT status, count(*)
FROM
(
  SELECT 
    ROW_NUMBER() OVER(PARTITION BY status ORDER BY &lt;some_id&gt; ASC) rnum,
    status
  FROM customers
) weirdness
GROUP BY status, (rnum-1)/500;