title: Separating SQL Results Into Ranges
body: <p>I would like to take a simple query on a list of members that are indexed by a number and group them into 'buckets' of equal size.  So the base query is:</p>
  
  <pre><code>select my_members.member_index from my_members where my_members.active=1;
  </code></pre>
  
  <p>Say I get 1000 member index numbers back, now I want to split them into 10 equally sized groups by a max and min member index.  Something like:</p>
  
  <p>Active members in 0    through 400  : 100
   Active members in 401  through 577  : 100
   ...
   Active members in 1584 through 1765 : 100</p>
  
  <p>The best I could come up with is repeatedly querying for the max(my_members.member_index) with an increasing rownum limit:</p>
  
  <pre><code>  for r in 1 .. 10 loop
    select max(my_members.member_index)
    into ranges(r)
    from my_members
     where  my_members.active = 1
     and rownum &lt; top_row
     order by my_members.member_index asc;
     top_row    := top_row + 100;
    end loop;
  </code></pre>