我有以下物品:
- 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
子句中使用cast
和order by
进行排序。
select * from table
order by
cast(SUBSTRING_INDEX( title, ', Ep. ', -1 ) as decimal);
关于python - 如何正确排序带数字的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22433188/