我不知道是否可能我有这样的主题代码叮咬
Math 451
Math 451a
Math 452
Math 452a
Math 452b
我想查询将这些字符串排序为
Math 451
Math 452
Math 451a
Math 452a
Math 452b
我试过
CAST(SUBSTR(subjects.code,INSTR(subjects.code, " ") + 1) AS UNSIGNED)
但没有按预期工作 感谢您的任何帮助和建议
答案 0 :(得分:1)
您可以先按字符串长度排序,然后按字符串本身排序:
SELECT code
FROM subjects
ORDER BY LENGTH(code), code;
<强> Rextester Demo 强>