1

在我们的语句末尾使用 HAVING 子句时,我们很难弄清楚为什么我们不能 COUNT 。

此语句返回结果:

SELECT lid, cid, title, url, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage, ns_compat, ns_des_img, ( (2.0 * (MATCH(title) AGAINST ('fsx concorde' IN BOOLEAN MODE))) + (1.0 * (MATCH(description) AGAINST ('fsx concorde' IN BOOLEAN MODE))) + (0.5 * (MATCH(url) AGAINST ('fsx concorde' IN BOOLEAN MODE))) ) AS relevance FROM nuke_downloads_downloads WHERE ( MATCH(title,description,url) AGAINST ('fsx concorde' IN BOOLEAN MODE) ) HAVING relevance > 3.0 ORDER BY relevance DESC

此语句不返回任何内容

SELECT COUNT(*) as num, lid, cid, title, url, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage, ns_compat, ns_des_img, ( (2.0 * (MATCH(title) AGAINST ('fsx concorde' IN BOOLEAN MODE))) + (1.0 * (MATCH(description) AGAINST ('fsx concorde' IN BOOLEAN MODE))) + (0.5 * (MATCH(url) AGAINST ('fsx concorde' IN BOOLEAN MODE))) ) AS relevance FROM nuke_downloads_downloads WHERE ( MATCH(title,description,url) AGAINST ('fsx concorde' IN BOOLEAN MODE) ) HAVING relevance > 3.0 ORDER BY relevance DESC

我们在这里遗漏了什么吗?

非常感谢您的帮助,并在此先感谢您。

4

1 回答 1

2

如果您只需要第一个查询将返回的行数,则可以将查询封装到派生表中。

您可以跳过除列表中的 和 之外的relevance所有SELECTORDER BY

SELECT COUNT(*)
FROM
  ( SELECT ( (2.0 * (MATCH ... ) AS relevance 
    FROM ...                                     -- unchanged
    WHERE ...                                    -- unchanged
    HAVING relevance > 3.0
                                                 -- ORDER BY removed    
  ) AS t ;
于 2013-09-20T13:50:22.797 回答