Natural Sort in MySQL

后端 未结 21 1114
南旧
南旧 2020-11-22 02:25

Is there an elegant way to have performant, natural sorting in a MySQL database?

For example if I have this data set:

  • Final Fantasy
  • Final Fant
21条回答
  •  自闭症患者
    2020-11-22 02:53

    Here is a quick solution:

    SELECT alphanumeric, 
           integer
    FROM sorting_test
    ORDER BY LENGTH(alphanumeric), alphanumeric
    

提交回复
热议问题