MySQL 模糊查询按匹配度排序
// 查询 title 包含 "中国" 或 "好声音" 的内容,并按匹配度排序
select * from xxx
where
title like '%中国%'
or
title like '%好声音%'
order by
case when title like '%中国%' then 1 else 0 end +
case when title like '%好声音%' then 1 else 0 end
// 查询 title 包含 "中国" 或 "好声音" 的内容,并按匹配度排序
select * from xxx
where
title like '%中国%'
or
title like '%好声音%'
order by
case when title like '%中国%' then 1 else 0 end +
case when title like '%好声音%' then 1 else 0 end