文章詳情頁
mysql如何按權重查詢數據啊?
瀏覽:92日期:2022-06-14 08:54:27
問題描述
假設表a有一個字段b,b存的是權重,范圍0-100吧,我想隨機查一條記錄,但是按權重給出數據,該如何寫呢
問題解答
回答1:select * from a order by b desc
返回的結果集越前面的權重越高比如
--------------|b | 其余字段|--------------|100| xxxxxxx|--------------|97| xxxxxxx|--------------|6 | xxxxxxx|--------------|5 | xxxxxxx|-------------回答2:
如果數據不多的話select *from a order by rand() limit 1
回答3:只取一條數據你還排什么序… 只隨機取一條就完了 樓上的就是 要取多條才需要排序sql套一層就好 select * from (select * from a order by rand() limit n) aa order by b desc;
相關文章:
排行榜
