title: Interleave rows of MySQL table
body: <p>I have a table containing data and a class, something like</p>
  
  <pre><code>----------------
  | DATA | Class |
  ----------------
  |  1   |   A   |
  |  2   |   A   |
  |  5   |   B   |
  |  10  |   A   |
  |  2   |   A   |
  |  45  |   B   |
  |  90  |   B   |
  ----------------
  </code></pre>
  
  <p>I would like to interleave the two classes to obtain something like this:</p>
  
  <pre><code>----------------
  | DATA | Class |
  ----------------
  |  1   |   A   |
  |  5   |   B   |
  |  2   |   A   |
  |  45  |   B   |
  |  2   |   A   |
  |  90  |   B   |
  |  10  |   A   |
  ----------------
  </code></pre>
  
  <p>I thought about generating on the fly an additional column that will add a sequential incrementing index to each separate class and sort on that one, but need a good direction/pointer to do that.</p>
  
  <p>Something like:</p>
  
  <pre><code>-----------------------
  | DATA | Class | indx |
  -----------------------
  |  1   |   A   |  1   |
  |  5   |   B   |  1   |
  |  2   |   A   |  2   |
  |  45  |   B   |  2   |
  |  2   |   A   |  3   |
  |  90  |   B   |  3   |
  |  10  |   A   |  4   |
  -----------------------
  </code></pre>
  
  <p>Is it even possible using only MySQL?</p>