|
-
Dec 2nd, 2002, 12:54 PM
#1
Thread Starter
Addicted Member
SELECT TOP and Random results
Just discovered how to randomze results from a QUERY.
E.G
Select TOP 100 *
from tblCDs
ORDER BY Rnd(CDID)
Works a treat. Get me 100 random CDs from my collection.
BUT..what I would like to do is try and ensure the spread across the CDs is as even as possible;
i.e 10% Rock, 10% Dance, 10% Classical etc.
Any ideas would be great...
Thanks
-
Dec 2nd, 2002, 02:34 PM
#2
You could use the union clause. You will need to adjust each Top 10 Percent line to get 100 records. Ie if you have 4 music types you would Select Top 25 Percent of each type.
Select TOP 10 PERCENT *
from tblCDs
Where MusicType = 'Rock'
ORDER BY Rnd(CDID)
Union All
Select TOP 10 PERCENT *
from tblCDs
Where MusicType = 'Classical'
ORDER BY Rnd(CDID)
etc..
-
Dec 2nd, 2002, 02:37 PM
#3
oops! What was I thinking. The Top X Percent solution will not work. But doing a Union for each music type will work.
Select TOP 10 *
from tblCDs
Where MusicType = 'Rock'
ORDER BY Rnd(CDID)
Union All
Select TOP 10 *
from tblCDs
Where MusicType = 'Classical'
ORDER BY Rnd(CDID)
-
Dec 3rd, 2002, 03:16 AM
#4
Thread Starter
Addicted Member
Thanks...
This will do the trick...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|