I have a problem in hand and that is to fetch a result set in a numeric pattern / sequence based on a single column's value.
Say I have the following table:
+-------+
| val |
+-------+
| 1 |
| 1 |
| 1 |
| 1 |
| 2 |
| 2 |
| 2 |
| 2 |
| 3 |
| 3 |
| 3 |
| 3 |
+-------+
How can I make it this way instead:
+-------+
| val |
+-------+
| 1 |
| 2 |
| 3 |
| 1 |
| 2 |
| 3 |
| 1 |
| 2 |
| 3 |
| 1 |
| 2 |
| 3 |
+-------+
Case mentioned by aularon:
What if one of the values do not have enough to fill the gaps, what is the expected behaviour? Say we replace two of the 3's to be 8's
+-------+
| val |
+-------+
| 1 |
| 1 |
| 1 |
| 1 |
| 2 |
| 2 |
| 2 |
| 2 |
| 3 |
| 3 |
| 8 |
| 8 |
+-------+
I'd still expect it to go in numeric sequence of smallest first, then largest, then smallest, then largest.
+-------+
| val |
+-------+
| 1 |
| 2 |
| 3 |
| 8 |
| 1 |
| 2 |
| 3 |
| 8 |
| 1 |
| 2 |
| 1 |
| 2 |
+-------+