最近在做全文搜索,有时候会用到一些复杂的需求,最近就遇到了个
一个表page,里面有id,url,title,body4个字段,求一个sql(注意是一个)把url,title,body里含有如'test'字段里的记录取出来,并且url匹配的在前,title匹配在中,body匹配的在后,小弟我的解决方法是用union,但效率太低,求大虾指点迷津
我的解决方法如下select * from(select * from page p where p.url like '%test%' 
union 
select * from page b where b.title like '%test%' 
union 
select * from page c where c.body like '%test%'
)
order by url desc,title desc,body desc