mysql - sql order by rand() with highest value shown more frequently -
as title describes, im looking write sql (mysql db) thats displays random records highest value shown more others. select cpc advertisement order rand(), cpc desc the above code not work expected. heres im after: i have 10 advertisers each setting own cpc (cost per click) budget. advertiser heighest budget have his/hers advert show more others, yet being random. user_id | cpc | ------------------ 1 | 0.10 | 2 | 0.03 | 3 | 0.20 | 4 | 0.04 | 5 | 0.55 | 6 | 0.12 | so user 5 have advert displayed more freqently others 5, 3, 6, 1, 4, 2 - in order of impressions respectively. bit assume google adwords work, higher users budget more impressions he/she have. i know no 1 likes rand() due performance have no more 100 advertisers. regards i best way so: select user_id, cpc advertisement order rand() * cpc desc this make adverts appear randomly, user_id 5 theoretically appear 5.5x more user_id 1, fair.