ORDER BY soundex 与 WHERE (MySql)
ORDER BY soundex with WHERE (MySql)
查询代码:
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%'
的结果
感谢关注
您可以在 order by
中使用布尔表达式。 "true" 被视为“1”,false 被视为“0”。所以:
ORDER BY (name LIKE '%test%') DESC,
(SOUNDEX(name) LIKE 'T23%') DESC,
(SOUNDEX(name) LIKE 'T230%') DESC
查询代码:
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%'
感谢关注
您可以在 order by
中使用布尔表达式。 "true" 被视为“1”,false 被视为“0”。所以:
ORDER BY (name LIKE '%test%') DESC,
(SOUNDEX(name) LIKE 'T23%') DESC,
(SOUNDEX(name) LIKE 'T230%') DESC