mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-09 20:30:01
mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序
mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序:本文章來為各位介紹一篇關(guān)于mysql 實(shí)現(xiàn)按 where in () 中的順序排序,用find_in_set() 函數(shù)的教程,希望此教程能夠?qū)Ω魑挥兴鶐椭? select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order
導(dǎo)讀mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序:本文章來為各位介紹一篇關(guān)于mysql 實(shí)現(xiàn)按 where in () 中的順序排序,用find_in_set() 函數(shù)的教程,希望此教程能夠?qū)Ω魑挥兴鶐椭? select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order

本文章來為各位介紹一篇關(guān)于mysql 實(shí)現(xiàn)按 where in () 中的順序排序,用find_in_set() 函數(shù)的教程,希望此教程能夠?qū)Ω魑挥兴鶐椭?br />
select * from table where id in ('783',' 769',' 814',' 1577',' 1769')
order by find_in_set( id, '783, 769, 814, 1577, 1769' )
查出來:
為什么不是 783 769 814 1577 1769 的順序?
注意:經(jīng)查找后原因出在find_in_set里面,如果find_in_set的第二個參數(shù)中有空格將導(dǎo)致順序亂掉,因?yàn)閙ysql查詢之前不會給你trim空格符。
so...
去空格后:
select * from table where id in ('783',' 769',' 814',' 1577',' 1769')
order by find_in_set( id, '783,769,814,1577,1769' )
注意只是去掉了
'783,769,814,1577,1769' 中的空格
再查出來:
783
769
814
1577
1769
至此我們實(shí)現(xiàn)用where in find_in_set 的排序,find_in_set 還可實(shí)現(xiàn)多條件排序 試試哦
總結(jié)
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序
mysql通過find_in_set()函數(shù)實(shí)現(xiàn)wherein()順序排序:本文章來為各位介紹一篇關(guān)于mysql 實(shí)現(xiàn)按 where in () 中的順序排序,用find_in_set() 函數(shù)的教程,希望此教程能夠?qū)Ω魑挥兴鶐椭? select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order