按案例排序

时间:2012-04-17 03:54:47

标签: mysql sql sql-order-by

这是一个有效的SQL语句

select title
from table
order by case when title like "%string%" then 0 else 1 end asc

如果我使用title = "string",我会得到有效的结果。 如何更改此值以使其接受%string%

1 个答案:

答案 0 :(得分:1)

select title
from table
order by case when title regexp "string" then 0 else 1 end asc;
  
    

我不会将其作为 ^string ,因为您正在搜索 %string%