Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL全文搜索仅得分高于零_Mysql_Sql_Mariadb - Fatal编程技术网

MySQL全文搜索仅得分高于零

MySQL全文搜索仅得分高于零,mysql,sql,mariadb,Mysql,Sql,Mariadb,如果我有这样的全文查询: SELECT title, MATCH(question) AGAINST ('string') AS q_score, MATCH(answer) AGAINST ('string') AS a_score, MATCH(keywords) AGAINST ('string') AS kw_score FROM helptable ORDER BY (4 * q_score) + (1 * a_score) + (2 * kw_score) D

如果我有这样的全文查询:

SELECT title,
   MATCH(question) AGAINST ('string') AS q_score,
   MATCH(answer) AGAINST ('string') AS a_score,
   MATCH(keywords) AGAINST ('string') AS kw_score FROM helptable
   ORDER BY (4 * q_score) + (1 * a_score) + (2 * kw_score) DESC
这就行了,我得到了一个相关性排名结果

但是,我不希望任何结果的综合得分为0。但当我尝试添加以下内容时:

   WHERE a_score > 0
它不起作用(“where子句”中的“a#u分数”未知列)。有没有其他方法可以做到这一点?谢谢大家!


(MariaDB 10.4.10,InnoDB表)

您可以使用
having
子句:

SELECT title,
       MATCH(question) AGAINST ('string') AS q_score,
       MATCH(answer) AGAINST ('string') AS a_score,
       MATCH(keywords) AGAINST ('string') AS kw_score
FROM helptable
HAVING a_score > 0
ORDER BY (4 * q_score) + (1 * a_score) + (2 * kw_score) DESC;
MySQL扩展了
HAVING
子句的使用,因此可以在非聚合查询中使用它。MySQL还允许在
HAVING
子句中使用列别名。瞧!这正是你想要的

我不确定你所说的“综合分数”是什么意思,但你也可以添加其他条件:

HAVING a_score > 0 OR kw_score > 0