| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor|
|column sorting, grouping, ordering and randomising all at once|
Split a column into two groups then order and randomise them
| 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
Any ideas please
| 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?
| 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 . . .
| 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 :)
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
© Webmaster World 1996-2013 all rights reserved