SQL多个关键字模糊查询(同一字段中)如何让尽量多的关键字相匹配的搜索结果在前面?
1个回答
展开全部
你用什么匹配的语法呢?
where a like '%1%' or a like '%2%' or a like '%3%'
这样?
那就这样,举个例子:
order by
case when a like '%1%' and a like '%2%' and a like '%3%' then 1
when a like '%1%' and a like '%2%'
or a like '%1%' and a like '%3%'
or a like '%2%' and a like '%3%' then 2
when a like '%1%' or a like '%2%' or a like '%3%' then 3
end
where a like '%1%' or a like '%2%' or a like '%3%'
这样?
那就这样,举个例子:
order by
case when a like '%1%' and a like '%2%' and a like '%3%' then 1
when a like '%1%' and a like '%2%'
or a like '%1%' and a like '%3%'
or a like '%2%' and a like '%3%' then 2
when a like '%1%' or a like '%2%' or a like '%3%' then 3
end
追问
付字符字符匹配任意组合,匹配最多的字符排在前面 用sql或者C#实现都可以
追答
想不出好办法。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询