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

I have a base group for the expression / 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;

Now I want to discard any results that have a higher average ping of 500. How can I do this ...?

+3
source share
1 answer

just add a sentence 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;
+13
source

Source: https://habr.com/ru/post/1737742/


All Articles