mysql按带点的数字排序

Tom*_*sik 1 mysql

我有一列名称为标题的行:

  • 1.8.8
  • 1.8.9
  • 1.9.1
  • 1.9.2
  • 1.8.10

我需要这样排序

  • 1.8.8
  • 1.8.9
  • 1.8.10
  • 1.9.1
  • 1.9.2

有什么办法吗?(列类型为 varchar)

Tom*_*Mac 5

笨重,但应该可以工作,前提是您的所有条目都采用 xxx 格式:

select yourColumn
from yourTable
order by
cast(substring_index(yourColumn,'.',1) as unsigned),
cast(substring_index(substring_index(yourColumn,'.',2),'.',-1) as unsigned),
cast(substring_index(substring_index(yourColumn,'.',3),'.',-1) as unsigned)
;
Run Code Online (Sandbox Code Playgroud)