题解 | #分组过滤练习题#

分组过滤练习题

http://www.nowcoder.com/practice/ddbcedcd9600403296038ee44a172f2d

两种方法

  • 使用having过滤函数联合查询结果
  • 使用子查询
# select university,avg(question_cnt) as avg_question_cnt,avg(answer_cnt) as avg_answer_cnt from user_profile
# group by university
# having avg(question_cnt)<5 or avg(answer_cnt)<20;

## 使用子查询
SELECT sp.university,sp.avg_question_cnt,sp.avg_answer_cnt FROM
(SELECT university,avg(question_cnt) as avg_question_cnt,
avg(answer_cnt) as avg_answer_cnt from user_profile
group by university) sp where 
sp.avg_question_cnt<5 or sp.avg_answer_cnt<20;

# select sp.university ,sp.avg_question,sp.avg_answer_cont
# from
# (select university,avg(question_cnt) as avg_question,
# avg(answer_cnt) as avg_answer_cont
# from user_profile
# group by university ) sp
# where sp.avg_question<5
# or sp.avg_answer_cont<20
全部评论

相关推荐

点赞 评论 收藏
分享
10-10 01:10
已编辑
深圳大学 测试开发
面了100年面试不知...:六月到九月,四个项目一个实习,是魔丸吗
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务