Natural Sort in MySQL

后端 未结 21 1089
南旧
南旧 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 03:11

    If you do not want to reinvent the wheel or have a headache with lot of code that does not work, just use Drupal Natural Sort ... Just run the SQL that comes zipped (MySQL or Postgre), and that's it. When making a query, simply order using:

    ... ORDER BY natsort_canon(column_name, 'natural')
    

提交回复
热议问题