本文章來為各位介紹一篇關(guān)于ing/try/14224.html">mysql/36415.html">mysql 實(shí)現(xiàn)按 where in () 中的順序排序,用find_in_set() 函數(shù)的教程,希望此教程能夠?qū)Ω魑挥兴鶐椭?/p>
select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order by find_in_set( id, '783, 769, 814, 1577, 1769' )
查出來:
76915778141769783
為什么不是 783 769 814 1577 1769 的順序?
注意:經(jīng)查找后原因出在find_in_set里面,如果find_in_set的第二個(gè)參數(shù)中有空格將導(dǎo)致順序亂掉,因?yàn)閙ysql查詢之前不會(huì)給你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' 中的空格
再查出來:78376981415771769
至此我們實(shí)現(xiàn)用where in find_in_set 的排序,find_in_set 還可實(shí)現(xiàn)多條件排序 試試哦
總結(jié)
以上就是本文關(guān)于mysql通過find_in_set()函數(shù)實(shí)現(xiàn)where in()順序排序的全部介紹,若有不足之處,歡迎大家留言指正。希望對(duì)大家有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選