你能在计算字段上有一个SQL where子句吗?

时间:2011-11-15 20:22:59

标签: sql

有没有办法做这样的事情:

 select Name, sum(Exceptions) exceptions from Results i
 where exceptions > 0
 group by (Name)

我将过滤掉计算总和字段中0的所有记录

我收到错误“无效使用聚合函数”

2 个答案:

答案 0 :(得分:4)

SELECT Name, SUM(Exceptions) AS exceptions
FROM Results AS r
GROUP BY (Name)
HAVING SUM(Exceptions) > 0

答案 1 :(得分:2)

select Name, sum(Exceptions) exceptions from Results i
group by (Name)
HAVING SUM(Exceptions) > 0

HAVING是一个where子句,适用于结果集的聚合行。