I want to create a mysql query that returns a result that is ordered by a certain column. The twist is that I want the order to be staggered instead of alphabetical or numeric. Say values for column_x for all records are either ‘a’,’b’,’c’, or ‘d’. Rather than the order being all ‘a’, then all ‘b’, … I want the order to be one ‘a’, followed by one ‘b’, followed by one ‘c’, etc. until it gets to ‘d’ and then starts over again. I know I can order by rand() but that’s not really what I want. I’ve racked my brains trying to figure this out but to no avail. I’m hoping I’m missing something obvious.
Share
This is what I think need to be done:
Create a rowrum for records in each group, use user defined varibles and logic in this example, to make sure numbers are reset for each alphagroup
Sort items in ascending order by the created rownum