比如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
嗯 就這么簡單~~