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

分组过滤练习题

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
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-27 17:41
牛客34884196...:你期望薪资4-5k,那确实可以重生了,但很难在深圳活下去
点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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