SQL分组依据:使用where子句逻辑基于聚合函数过滤结果
技术问答
218 人阅读
|
0 人回复
|
2023-09-14
|
我有一个基本的group by / avg语句:: s/ n$ I9 [% d
select url,avg(contentping tcpping),count(*) from websites ws,ping pi where ws.idwebsite = pi.idwebsite and errortype is nullgroup by url order by avg(contentping tcpping) asc;我现在想做的是删除任何平均值ping高500的结果。我该怎么办?…?
' i1 l. u) A6 V5 f0 p 2 H* [/ y. e5 y, @
解决方案:
" X# j" a T J( { 只需添加一个having子句:+ V1 V' Z* G" H/ ~% d
select url,avg(contentping tcpping),count(*) from websites ws,ping pi where ws.idwebsite = pi.idwebsite and errortype is nullgroup by url having avg(contenetping tcpping) < 500order by avg(contentping tcpping) asc; |
|
|
|
|
|