开发者

mysql selection preference

开发者 https://www.devze.com 2023-04-03 12:32 出处:网络
I\'m wanting to display random adverts on my front 开发者_运维技巧end that are selected from a table. Each advert has a score between 1 and 5. The higher the advert score, the more frequently it shoul

I'm wanting to display random adverts on my front 开发者_运维技巧end that are selected from a table. Each advert has a score between 1 and 5. The higher the advert score, the more frequently it should be selected

Is there any way I could achieve this in a query? So maybe something like

SELECT * FROM advert ORDER BY RAND(), (SOME MAGICAL PREFERENCE ORDERING) LIMIT 3

Thanks!


How about

SELECT * FROM advert ORDER BY RAND() * (SOME MAGICAL PREFERENCE ORDERING) DESC LIMIT 3
0

精彩评论

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

关注公众号