MySQL 如何按照指定字符串進行排序


比如mysql某個字段中有 無規則的字符串(比如json格式的數據等),如何對其進行排序呢?

使用以下方式即可:

ORDER BY case
WHEN spec_array like '%str_01%' then 1
WHEN spec_array like '%str_02%' then 2
WHEN spec_array like '%str_03%' then 3
WHEN spec_array like '%str_04%' then 4
WHEN spec_array like '%str_05%' then 5
WHEN spec_array like '%str_06%' then 6
WHEN spec_array like '%str_07%' then 7
WHEN spec_array like '%str_08%' then 8
end
asc

嗯 就這么簡單~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM