MySQL错误1054:having子句中的未知列

时间:2010-11-01 17:18:25

标签: sql mysql aggregate-functions mysql-error-1054

查询:

  SELECT SUM(ProductCost) 
    FROM `tblBasket` 
GROUP BY ProductCode
  HAVING BasketSessionID = '3429782d79c68834ea698bb4116eef5e'

显示错误:

  

1054 - 'having clause'中的未知列'BasketSessionID'

我的查询中有什么错误?

alt text

3 个答案:

答案 0 :(得分:11)

尝试使用where子句代替having子句:

SELECT SUM(ProductCost) 
FROM `tblBasket` 
WHERE BasketSessionID ='3429782d79c68834ea698bb4116eef5e'
GROUP BY ProductCode

答案 1 :(得分:2)

我认为你想使用没有的where子句。

答案 2 :(得分:2)

HAVING过滤掉聚合。你应该试试GROUP BY。