我有一个字符串类型的列,其中包含以下行中的值:
1-1
1-5
1-14
1-7
1-3
现在,如果我在该列上使用 ORDER BY,我得到的顺序为:
1-1
1-14
1-3
1-5
1-7
将其排序为 1-1, 1-3, 1-5,1-7,1-14
的正确方法是什么
谢谢你的时间
最佳答案
假设您的第一个字符也可能不同:
order by convert(substr(my_field, 1, locate(my_field, '-') - 1) as int),
convert(substr(my_field, locate(my_field, '-') + 1) as int)
关于sql - SQL 中的 ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692399/