Mysql字符串中有数字的排序问题

如有以下几条数据
(int) (text)
id col
1 中文1
2 中文4
3 中文22
4 中文2
5 中文3
现在直接order by col asc 则是
1 中文1
4 中文2
3 中文22
5 中文3
2 中文4
我想select出来这样
1 中文1
4 中文2
5 中文3
2 中文4
3 中文22

你的“中文”是固定的文字吗?

--下面的语句只支持9999以下的数字排序
select id,col, right(col,length(col)-LEAST(
    if(Locate('0',col) >0,Locate('0',col),9999),
    if(Locate('1',col) >0,Locate('1',col),9999),
    if(Locate('2',col) >0,Locate('2',col),9999),
    if(Locate('3',col) >0,Locate('3',col),9999),
    if(Locate('4',col) >0,Locate('4',col),9999),
    if(Locate('5',col) >0,Locate('5',col),9999),
    if(Locate('6',col) >0,Locate('6',col),9999),
    if(Locate('7',col) >0,Locate('7',col),9999),
    if(Locate('8',col) >0,Locate('8',col),9999),
    if(Locate('9',col) >0,Locate('9',col),9999)
  )-1) *1 a
   from test4 order by a

温馨提示:内容为网友见解,仅供参考
第1个回答  2020-06-23
order by 字段名称+0 desc/asc的形式进行排序order by 字段名称*1 desc/asc的形式进行排序
第2个回答  2013-09-26
SELECT id, col,LENGTH(col) FROM d ORDER BY LENGTH(col) ASC, col ASC

或者

SELECT id,col FROM d ORDER BY CAST(TRIM('中文' FROM col) AS SIGNED)

根据实际情况看吧本回答被网友采纳
第3个回答  2013-09-26
select * from 表名 order by substring(col,3,2)+0;
第4个回答  2020-09-01
select id col from xx order by cast(substring(col,5) as integer)
相似回答