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

嗯 就这么简单~~

posted @ 2017-02-17 17:34  抡起菜刀砍小强  阅读(5955)  评论(1编辑  收藏  举报