0

这是我的测试数据(MySQL)

test1
test2
test3
test10
test11
mytest

我想通过文本而不是以下数字(如果存在)来订购这些记录:

mytest
test1
test2
test3
test10
test11

当我使用 时Order By,我的数据被排序为文本,如下所示:

mytest
test1
test10
test11
test2
test3

谁能给我一个解决方案?

4

1 回答 1

0

在我的查询中,我将字母数字值与字符串值分开,然后结合结果,看看:

  select temp1.a col from
  (select a from tabl WHERE a not REGEXP '[0-9]' order by length(a)) temp1
  union all 
  select temp2.a  from
  (select a FROM tabl WHERE a REGEXP '[0-9]' order by length(a),a) temp2 ;
于 2015-04-21T10:10:32.460 回答