Mysql查询匹配和OR WHERE

时间:2012-11-29 19:59:57

标签: mysql sql

嗨如果有这个查询:

 SELECT *,
      MATCH(tags) AGAINST ('book library' IN BOOLEAN MODE) AS resources_score 
      FROM books  HAVING resources_score > 0 
      ORDER BY resources_score DESC, id DESC ; 

是否可以添加OR WHERE title LIKE ;

此外,由于我的查询是returnig resource_score 10,是否可以获得更高的查询/搜索/结果准确度?

最后,一个提示dubt,查询匹配准确度取决于记录数量?

感谢谁来帮助我

1 个答案:

答案 0 :(得分:1)

当所有其他方法都失败时,您可以使用算术组合SQL函数。

 SELECT *,
 (title LIKE '%pattern%') + (MATCH(tags) AGAINST ('book library' IN BOOLEAN MODE))
   AS resources_score 
 FROM books HAVING resources_score > 0 
 ORDER BY resources_score DESC, id DESC ;

当标题包含'pattern'时,这将为MATCH()返回的分数加1。