题解 | #分组过滤练习题#
分组过滤练习题
https://www.nowcoder.com/practice/ddbcedcd9600403296038ee44a172f2d
SELECT university, ROUND(AVG(question_cnt),3) AS avg_question_cnt,ROUND(AVG(answer_cnt),3) AS avg_answer_cnt FROM user_profile GROUP BY university HAVING avg_question_cnt<5 OR avg_answer_cnt <20
问题拆解:
- 要输出什么内容:university, ROUND(AVG(question_cnt),3) AS avg_question_cnt,ROUND(AVG(answer_cnt),3) AS avg_answer_cnt
- 从哪里输出:FROM user_profile
- 聚合函数的计算是按哪一列计算的:GROUP BY university
- 筛选条件是什么:HAVING avg_question_cnt<5 OR avg_answer_cnt <20
我认为大多数题目在求解时都可以先问自己这几个问题,然后根据SQL的常见模式填充补充细节即可!
#SQL练习#