Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MySQL中,先按数字再按字母对记录进行排序_Mysql_Sql_Regex_Mariadb - Fatal编程技术网

在MySQL中,先按数字再按字母对记录进行排序

在MySQL中,先按数字再按字母对记录进行排序,mysql,sql,regex,mariadb,Mysql,Sql,Regex,Mariadb,我有一个名为“test”的表,其中有一个名为“custom_id”的列,它可以是字母和整数的混合体。我想要一个MySQL查询,首先根据整数,然后根据字符串中的字母对其进行排序。即: Input: 1b 1a Apple5 Apple1 Bapple2 Bapple5 2a 3 Output (in ASC): 1a 1b Apple1 2a Bapple2 3 Apple5 Bapple5 上面的排序有点不同于自然排序,因为它不基于字符串的长度进行排序。我有以下在MariaDB中工作的查询,

我有一个名为“test”的表,其中有一个名为“custom_id”的列,它可以是字母和整数的混合体。我想要一个MySQL查询,首先根据整数,然后根据字符串中的字母对其进行排序。即:

Input:
1b
1a
Apple5
Apple1
Bapple2
Bapple5
2a
3

Output (in ASC):
1a
1b
Apple1
2a
Bapple2
3
Apple5
Bapple5
上面的排序有点不同于自然排序,因为它不基于字符串的长度进行排序。我有以下在MariaDB中工作的查询,但我正在寻找MySQL解决方案(请不要过程):


0+自定义_id
将给出前导数字的值。如果没有前导零,那么
LENGTH(0+自定义id)
将说明要去除多少。使用合适的
MID(…)
提取后面的字符

SELECT custom_id FROM test
ORDER BY CAST(REGEXP_SUBSTR(custom_id,'[0-9]+') AS UNSIGNED) ASC, custom_id ASC