where子句中的未知列xxx使用连接,分组依据和全文

时间:2012-04-06 01:43:36

标签: mysql sql join group-by mysql-error-1054

我的查询有什么问题?

SELECT ...
       MATCH(results.keywords) AGAINST('".DB::e($_POST['s'])."' IN BOOLEAN MODE) AS aaa,
       SUM( MATCH(tags.keywords) AGAINST('".DB::e($_POST['s'])."' IN BOOLEAN MODE) ) AS bbb
  FROM table1
  JOIN table2 ... JOIN table3 ...
 WHERE (aaa > 0   here the alias doesn't work!
        OR bbb > 0   here the alias doesn't work! )
GROUP BY table1.id
ORDER BY aaa DESC,  but here the alias works!
         bbb DESC  but here the alias works!

如果我删除WHERE子句完美地运行...那么我的别名有什么问题?

1 个答案:

答案 0 :(得分:4)

您需要使用HAVINGherehere,而不是那么有用:here);在别名存在之前评估WHERE子句;)