实际上,使用case语句制作一对标记可能是一个更好的解决方案:
select ..., case when keyword like '%' + @input + '%' then 1 else 0 end as keywordmatch, case when content like '%' + @input + '%' then 1 else 0 end as contentmatch-- or whatever check you use for the matchingfrom ... and here the rest of your usual matching query ... order by keywordmatch desc, contentmatch desc
同样,这仅在所有关键字匹配项的排名高于所有仅内容匹配项的情况下。我还假设关键字和内容的匹配都最高。



