order by soundex with where(mysql)

j13ufse2  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(363)

查询代码:

SELECT *
FROM example
WHERE name LIKE '%test%'
OR SOUNDEX(name) LIKE 'T230%'
OR SOUNDEX(name) LIKE 'T23%'

我想先展示与之匹配的结果 WHERE name LIKE '%test%' 之后呢 SOUNDEX(name) LIKE 'T230%' 最后一行是 SOUNDEX(name) LIKE 'T23%' 谢谢你的关注。

wwtsj6pe

wwtsj6pe1#

可以在中使用布尔表达式 order by . “true”被视为“1”,false被视为“0”。所以:

ORDER BY (name LIKE '%test%') DESC,
         (SOUNDEX(name) LIKE 'T23%') DESC,
         (SOUNDEX(name) LIKE 'T230%') DESC

相关问题