| column sorting, grouping, ordering and randomising all at once Split a column into two groups then order and randomise them |
Wayder

msg:4173652 | 10:04 pm on Jul 20, 2010 (gmt 0) | My SQL 4.1.25 I am totally stumped with this one. I have a table in which one of the columns is an integer from 0~10. I am trying to split that it into two groups. 1-5 and 0 + 6-10 and order them firstly group 0 + 6-10 then group 1-5 with each group randomised. So basically I need to see something like this 10 7 8 0 7 6 9 6 0 10 2 4 5 2 5 3 1 Any ideas please
|
Wayder

msg:4173738 | 12:31 am on Jul 21, 2010 (gmt 0) | I came up with the following ORDER BY (my_number = 0 OR my_number > 5) DESC, RAND(),my_number ASC, RAND() Do you know a better/alternate way?
|
rocknbil

msg:4173742 | 12:36 am on Jul 21, 2010 (gmt 0) | Doesn't that work? It looks like it should, and is exactly how I would do it . . .
|
Wayder

msg:4173752 | 12:58 am on Jul 21, 2010 (gmt 0) | Yes, in fact it works better than I thought it would. I was just asking to find out if anyone would do it a different way. More than one way to skin a cat and all that. I feel reasured that you said that's the way you would do it :) Thanks
|
|
|