开发者

SQL group by: using where-clause logic to filter results based on aggregate functions

I h开发者_如何转开发ave a basic group by/avg statement:

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;

What I want to do now is to drop any results which have a higher than average ping of 500. How can I do this...?


just add a having clause:

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜