题解 | #得分不小于平均分的最低分#
得分不小于平均分的最低分
https://www.nowcoder.com/practice/3de23f1204694e74b7deef08922805b2
本题思路:
- 首先,通过两表连接并进行聚合计算查询出SQL类型考试中非空分数的平均值
- 其次,利用求得平均值作为筛选条件之一得到最终筛选区域
- 最后,筛选出大于平均值的最小分数。
select min(score) min_score_over_avg from exam_record t1 right join examination_info t2 // 从筛选后的数据查询最小的分数 on t1.exam_id = t2.exam_id // 使用exam_id作为主表进行外连接,以获取每个用户id的tag进而作为筛选条件 where tag = 'SQL' and score is not null // 最小值的筛选同样需要保证不为空 and score >= (select avg(score) from exam_record t1 right join examination_info t2 // 筛选SQL类型不为空的分数中的平均值 on t1.exam_id = t2.exam_id where tag = 'SQL' and score is not null)