牛客网题目:表user_profile,查看每个学校用户的平均发贴和回帖情况,寻找低活跃度学校进行重点运营,请取出平均发贴数低于5的学校或平均回帖数小于20的学校。
如果用where,则需要用到子查询语句:
select *
from
(select
university,
avg(question_cnt) as avg_question_cnt,
avg(answer_cnt) as avg_answer_cnt
from user_profile
group by university) as t
where t.avg_question_cnt<5 or t.avg_answer_cnt<20
如果想用
聚合函数结果 avg(question_cnt)<5 or avg(answer_cnt)<20作为筛选条件,则不能用where,而是用having语句。
错误:
select uni