比如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
嗯 就这么简单~~