title: Grouping by row number in a column
body: <p>Let’s say you have this set of records on a database:</p>
  
  <pre><code>PartNumber     Qty    Group  
     A           1       1   
     B           2       1
     C           3       1
     B           4       1
     a           1       2
     B           2       2
     C           3       2
     B           4       2
  </code></pre>
  
  <p>How can we come up with this result:     </p>
  
  <pre><code>   A       2
     B       4
     C       6
     B       8
  </code></pre>
  
  <p>That is, adding the first row of the first group with the first row of the second group, the second row of the first group with the second row of the second group, the third row of the first group with the third row of the second group and so on. </p>
  
  <p>Notes:<br>
  *- I can have multiples groups<br>
  *- The groups will always have the same length (i.e the same number of rows PER GROUP)<br>
  *- The partnumbers in the group will always be the same in the same order<br>
  *- I can have multiples partnumber repeat, i.e not only B repeat but all of them PER GROUP  </p>
  
  <p>I know I can add a new column to the table to have something like this:</p>
  
  <pre><code>PartNumber    Qty    Group    idx
     A          1       1       1
     B          2       1       2
     C          3       1       3
     B          4       1       4
     a          1       2       1
     B          2       2       2
     C          3       2       3
     B          4       2       4
  </code></pre>
  
  <p>and: select partnumber, sum(qty) from table group by idx<br>
   but that's exactly what I can't do. Any suggestions? </p>