If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Any way to weight selections in queries?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-10, 15:04
DavyBoy DavyBoy is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
Any way to weight selections in queries?

Hello experts!

This is a knotty one that I've been puzzling over for some time.

I have a selection of users some of which are online and some of which are not. I can easily pull lists of users who are online (last seen in the last 20 minutes), and users who are offline and random users who may be online or offline.

Trouble is that there are *many* more users who are offline than online.

Is there any way to weight the query to make it more likely that an online user would appear in the selected batch? A selection doesn't *have* to have an online user every time, but it would good if they could pop up a bit more often.

With the current (simplified) select below you'd be lucky to see an online user in 20 or more batches. It would be nice to see an online user every 2 or 3 or more often if more are online.

Here's where I'm at so far...
Code:
SELECT 
nickname, 
userid, 
(UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(lastseen))/60 as timeon
from users
left join lastseen on users.userid=lastseen.userid
order by rand()
limit 0,20
Also the ordering by rand() is going to become an issue as the database grows so any hints on that too would help!

Many thanks in advance for any pointers.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On