我有以下物品:

- Orange Is the New Black, Season 1, Ep. 1 -- I Wasn't Ready
- Orange Is the New Black, Season 1, Ep. 10 -- Bora Bora Bora
- Orange Is the New Black, Season 1, Ep. 2 -- Tit Punch

目前,我正在做SELECT title FROM table ORDER BY title
在mysql中如何正确订购?也就是说,结果是:
- Orange Is the New Black, Season 1, Ep. 1 -- I Wasn't Ready
- Orange Is the New Black, Season 1, Ep. 2 -- Tit Punch
- Orange Is the New Black, Season 1, Ep. 10 -- Bora Bora Bora

最佳答案

只要title标记的格式没有改变,
您可以在substring_index子句中使用castorder by进行排序。

select * from table
order by
cast(SUBSTRING_INDEX( title, ', Ep. ', -1 ) as decimal);

关于python - 如何正确排序带数字的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22433188/

10-11 05:04