为什么使用“ HAVING”而不是“ WHERE”不会得到相同的结果?

时间:2019-09-09 14:56:56

标签: mysql sql

SELECT
  `name`,
  MATCH (`name`) AGAINST ('"gold"' IN BOOLEAN MODE) as score
FROM
foo
WHERE 
  group = '1' 
  AND  MATCH (`name`) AGAINST ('"gold"' IN BOOLEAN MODE) 
ORDER BY score;

返回4个结果:

name            | score
----------------|--------------------
Nice Gold       | 0.06243875250220299
Super Nice gold | 0.06243875250220299
Ugly gold       | 0.06243875250220299
Fancy gold      | 0.06243875250220299

现在,我想在score子句中使用WHERE别名来提高可读性,但是由于WHERE无法识别它,因此我使用HAVING

SELECT
  `name`,
  MATCH (`name`) AGAINST ('"gold"' IN BOOLEAN MODE) as score
FROM
foo
WHERE group = '1'
HAVING score > 0
ORDER BY score;

现在,一些结果确实很奇怪:

name            | score
----------------|--------------------
Nice Gold       | 0.06243875250220299
Super Nice gold | 0.06243875250220299
Nice Diamond    | 0
Custom          | 0
Ugly gold       | 0.06243875250220299
Fancy gold      | 0.06243875250220299

为什么显示Nice DiamondCustom?我在AWS RDS上使用Aurora MySql。

0 个答案:

没有答案