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

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

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

先上完整代码


select min(e_r.score) as min_score_over_avg
from exam_record e_r join examination_info e_i
on e_r.exam_id = e_i.exam_id
where e_i.tag = 'SQL'
and score >= (select avg(e1.score)
             from exam_record e1 join examination_info e2
             on e1.exam_id = e2.exam_id
             where tag = 'SQL'
             )

最开始我想的是

select min(e_r.score) as min_score_over_avg
from exam_record e_r join examination_info e_i
on e_r.exam_id = e_i.exam_id
where e_i.tag = 'SQL'
and score >= avg(score)

但是发现好像不能这样用,想了想语句的逻辑顺序也就知道了,

所以我就打算整个视图,也算是实践知识就是


create or replace  view  total
as
select e_r.id,e_r.exam_id,e_i.tag,e_r.score
FROM
    exam_record e_r
        LEFT JOIN
    examination_info e_i
    ON
    e_r.exam_id = e_i.exam_id
where tag = 'SQL';


SELECT
    min(total.score) min_score_over_avg
FROM
    total
where
        total.score >= (
            select avg(score)
            from total
        )

但是能在我的mysql运行不能在判题系统运行。。。没事会就行。

全部评论

相关推荐

2025-12-06 16:17
济宁学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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