SQL group by: using where-clause logic to filter r

2020-07-22 04:01发布

I have 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...?

1条回答
一夜七次
2楼-- · 2020-07-22 04:20

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;
查看更多
登录 后发表回答