Still new to asking questions here, so this is my second attempt at a problem I face.
I have a table that is already ordered by Score. Every record can be one of 3 types. I would like to reorder the table by Score but impose an additional restriction on the mix, in every 10 records. Particularly, there is a specific mix consisting of each of the 3 types.
In the example below, I want to have at least 2 of type C and at most 2 of type A
What I have
------------------------------------------
ID Score Type
------------------------------------------
1 100 A
2 99 B
3 97 B
4 92 A
5 91 C
6 85 A
7 83 B
8 81 B
9 75 B
10 70 B
11 65 A
12 61 C
13 59 B
What I want
------------------------------------------
ID Score Type
-----------------------------------------
1 100 A
2 99 B
3 97 B
4 92 A
5 91 C
7 83 B
8 81 B
9 75 B
10 70 B
12 61 C
I don't think this can be solved by Group By or usort in an efficient manner. My initial solution was to export to PHP and do the reordering there.