先按字母顺序排列,然后按数字顺序排列 [英] ORDER BY alphabet first then follow by number
本文介绍了先按字母顺序排列,然后按数字顺序排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mysql排序中寻找一些调整,我通常从表中选择记录,然后通过Name(varchar)ASC对记录进行排序,但数字始终排在首位
I looking for some tweak in mysql ordering , I normally select record from table and then order the record by Name(varchar) ASC but the number is always come first
这是我的问题的一些示例(请注意.mysql首先以0-9排序记录)
here some example of my question (note. mysql sort the record with 0-9 first)
SELECT name FROM list ORDER BY name ASC
record returned:
1 star
2 star
9 slice
Ape
Age
Beg
Bell
Fish
Zoo
我想要的是字母顺序,然后是数字
所需的输出
Ape
Age
Beg
Bell
Fish
Zoo
1 star
2 star
9 slice
推荐答案
使用以下ORDER BY
子句:
ORDER BY IF(name RLIKE '^[a-z]', 1, 2), name
这篇关于先按字母顺序排列,然后按数字顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文