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

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

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 (查询)
这样这个表名就可以复用了。

窗口函数方式:

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:15
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司8个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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