homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved