题解 | #得分不小于平均分的最低分#
得分不小于平均分的最低分
https://www.nowcoder.com/practice/3de23f1204694e74b7deef08922805b2
解题点 求出SQL试题的平均分,然后让分数与其比较,然后找出最小值。
思路点,知道子查询可以用在where 中的运算判断中。
with t2 as (select t.* from exam_record t join examination_info t1 using(exam_id) where tag = "SQL") select min(score) from t2 where score >= (select avg(score) from t2)
自己最开始想到的是利用select 子查询,做出来后觉得不够简洁。
with t2 as (select t.* from exam_record t join examination_info t1 using(exam_id) where tag = "SQL") select min(score) from ( select *,(select avg(score) from t2) as avg_1 from t2)t3 where score >=avg_1
with 是临时表,句式位 with 表名 as (查询)
这样这个表名就可以复用了。
窗口函数方式:
略