开发者

Randomly (with weight bias) select row from database? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

MySQL: Select Random Entry, but Weight Towards Certain Entries

I have a table that I would like to be able to randomly select a user from, but in this table I have an 'Entries' column. I have been able to randomly select a user, but now I am trying to take into account their number of entries (higher the number, the more likely they are to win). How would I go about doing this?

My table looks so开发者_开发技巧mething like:

FN   | LN    | ENTRIES
Bob  | Smith | 20
John | Doe   | 3

Thanks for your help!


To weight them, multiply rand() by the entries column..

select * from table order by entries*rand() desc limit 1; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜