SQL group by:使用where子句逻辑根据聚合函数过滤结果

时间:2010-03-19 21:10:50

标签: sql mysql where-clause

我有/ avg声明的基本组:

select url, avg(contentping+tcpping), count(*) from websites ws, ping pi 
where ws.idwebsite = pi.idwebsite and errortype is null
group by url order by avg(contentping+tcpping) asc;

我现在要做的是删除任何高于平均ping 500的结果。我该怎么做...?

1 个答案:

答案 0 :(得分:13)

只需添加having子句:

select url, avg(contentping+tcpping), count(*) from websites ws, ping pi 
where ws.idwebsite = pi.idwebsite and errortype is null
group by url 
having avg(contenetping+tcpping) < 500
order by avg(contentping+tcpping) asc;