文章詳情頁
mysql如何按權(quán)重查詢數(shù)據(jù)啊?
瀏覽:248日期:2022-06-14 08:54:27
問題描述
假設(shè)表a有一個(gè)字段b,b存的是權(quán)重,范圍0-100吧,我想隨機(jī)查一條記錄,但是按權(quán)重給出數(shù)據(jù),該如何寫呢
問題解答
回答1:select * from a order by b desc
返回的結(jié)果集越前面的權(quán)重越高比如
--------------|b | 其余字段|--------------|100| xxxxxxx|--------------|97| xxxxxxx|--------------|6 | xxxxxxx|--------------|5 | xxxxxxx|-------------回答2:
如果數(shù)據(jù)不多的話select *from a order by rand() limit 1
回答3:只取一條數(shù)據(jù)你還排什么序… 只隨機(jī)取一條就完了 樓上的就是 要取多條才需要排序sql套一層就好 select * from (select * from a order by rand() limit n) aa order by b desc;
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個(gè)布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語法錯(cuò)誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?
排行榜

熱門標(biāo)簽
網(wǎng)公網(wǎng)安備