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

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

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

窗口函数方式:

全部评论

相关推荐

12-13 12:11
复旦大学 Java
点赞 评论 收藏
分享
12-15 14:16
门头沟学院 Java
回家当保安:发offer的时候会背调学信网,最好不要这样。 “27届 ”和“28届以下 ”公司招聘的预期是不一样的。
实习简历求拷打
点赞 评论 收藏
分享
八极星:有什么不能问的,(/_\),这又不是多珍贵的机会,你有什么可失去的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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