题解 | #得分不小于平均分的最低分#

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

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

#SQL试卷(where)得分不小于(and)该类试卷平均得分(avg)的用户最低得分
#先求出SQL试卷的平均得分 
#select avg(score) from exam_record er join examination_info info using(exam_id) where info.tag='SQL' and score is not null
select score from exam_record er
inner join examination_info info
using(exam_id)
where score>=(select avg(score) from exam_record er join examination_info info using(exam_id) where info.tag='SQL' and score is not null)
and info.tag='SQL'
order by score
limit 1;

思路:

1、拆解题目:求SQL试卷得分 大于等于 平均分(这个平均分有诸多限制条件)的最低得分

2、依次写代码:

首先,找到这个平均分(即上面写的)

其次,写出SQL试卷得分大于等于平均分的所有得分

最后,用按分数排序order by score 和 limit 1 得到最低得分

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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