title: How to group into batches after assigning rank
body: <p>I have a table that I'm first trying to group based on unique column values (using <code>dense_rank</code>) and then further group those items into batches of 5. Below is my table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>video_id</th>
  <th>frame_id</th>
  <th>verb</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>video_a</td>
  <td>frame_1</td>
  <td>walk</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_2</td>
  <td>run</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_3</td>
  <td>sit</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_4</td>
  <td>walk</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_5</td>
  <td>walk</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_6</td>
  <td>walk</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_7</td>
  <td>stand</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_8</td>
  <td>stand</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_9</td>
  <td>run</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_10</td>
  <td>run</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_11</td>
  <td>sit</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_12</td>
  <td>run</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_13</td>
  <td>run</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And below is what I'm trying to get:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>video_id</th>
  <th>frame_id</th>
  <th>verb</th>
  <th>batch_of_five</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>video_a</td>
  <td>frame_1</td>
  <td>walk</td>
  <td>1</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_2</td>
  <td>run</td>
  <td>1</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_3</td>
  <td>sit</td>
  <td>1</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_4</td>
  <td>walk</td>
  <td>1</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_5</td>
  <td>walk</td>
  <td>1</td>
  </tr>
  <tr>
  <td>video_a</td>
  <td>frame_6</td>
  <td>walk</td>
  <td>2</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_7</td>
  <td>stand</td>
  <td>3</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_8</td>
  <td>stand</td>
  <td>3</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_9</td>
  <td>run</td>
  <td>3</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_10</td>
  <td>run</td>
  <td>3</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_11</td>
  <td>sit</td>
  <td>3</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_12</td>
  <td>run</td>
  <td>4</td>
  </tr>
  <tr>
  <td>video_b</td>
  <td>frame_13</td>
  <td>run</td>
  <td>4</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Where each <code>video_id</code> has a unique rank and each batch of 10 within each ranked <code>video_id</code> has its own unique rank (and each batch of 10 overall has a unique id regardless of whether they belong to the same <code>video_id</code> or not).</p>
  <p>I'm able to group based on the <code>video_id</code> column but am having trouble grouping those items further so that they are both in batches of 10 and unique across all <code>video_ids</code>. I thought about using a group by clause but I'm trying to keep the other columns intact as well (<code>verb</code> column).</p>
  <p>Here is my presto query so far:</p>
  <pre><code>SELECT
      *
  FROM (
      SELECT
          *,
          -- Give each unique video_id a unique rank
          DENSE_RANK() OVER (ORDER BY video_id) AS video_batch
      FROM videos
  )
  
  </code></pre>