MySQL排序方式,从一个单词开始,然后按字母顺序排列


mysql order by, starting with a word, then alphabetically

我正在尝试做一个mysql查询,它将用以"timberwood"开头的标题对我的结果进行排序,首先开始,然后从那里开始按字母顺序排列。这可能吗?还是我需要以某种方式在 php 中重新组织它?这是我尝试使用的代码,但它没有按照我想要的方式排序。

SELECT *, (case when `title` like "timberwood%" then substring(title,6) else title end) as testing FROM #__downloads_items WHERE state = 1 ORDER BY testing asc 

任何帮助将不胜感激!

这应该可以解决它:

Order by case when title like 'timberwood%' then 0 else 1 end asc, title asc

对于以"timberwood%"开头的任何内容,"case when"将给出值 0,然后对于其他任何内容,值为 1。由于这是首先要排序的内容,因此所有"木材百分比"结果都应排在首位。