题解 | 不低于平均分的最低分

得分不小于平均分的最低分

http://www.nowcoder.com/practice/3de23f1204694e74b7deef08922805b2

别人写的都挺好,我只是分享一下我的思路以及犯的错误: 1.要审题,题目要求是"SQL"比较,那么就需要两张表进行联表; from exam_record a left join examination_info b on a.exam_id = b.exam_id where b.tag = 'SQL' 2.比较的是平均成绩,那么需要先查询"SQL"的平均分 select sum(a.score)/count(a.score) from exam_record a left join examination_info b on a.exam_id = b.exam_id where b.tag = 'SQL'; (备注:个人觉得在这里直接用avg聚合不是很好,勿喷~) 3.题目要求是不低于平均分的最低分,那么思路就是先求大于等于平均分的记录,然后再求最低的,为了方便,我们通过where...and...进行操作

select min(x.score) as min_score_over_avg from exam_record x left join examination_info y on x.exam_id = y.exam_id where y.tag = 'SQL' and x.score >= (select sum(a.score)/count(a.score) from exam_record a left join examination_info b on a.exam_id = b.exam_id where b.tag = 'SQL');

全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
10-28 17:30
已编辑
华东交通大学 Java
想进开水团喝开水:字节的hr的本职工作就是黄金矿工
秋招笔试记录
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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