题解 | 73#考试分数(二)#

考试分数(二)

http://www.nowcoder.com/practice/f456dedf88a64f169aadd648491a27c1

第一版:

select * 
from grade g
where score>
(
    select a_score 
    from 
    (
        select avg(score) a_score,job 
        from grade 
        group by job
    ) t
    where g.job=t.job
)
order by id

第二版:

select * 
from grade g
where score>
(
    select avg(score) 
    from grade t
    where g.job=t.job
    group by job
)
order by id

思路:这个题有很多方法,第二版比第一版简洁,少了一个子查询,此题也可以用窗口函数来做。

sql题 文章被收录于专栏

牛客网里面的sql题,把答案和思路写下来

全部评论

相关推荐

07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
Lorn的意义:你这种岗位在中国现在要么牛马天天加班,要么关系户进去好吃好喝,8年时间,真的天翻地覆了,对于资本来说你就说一头体力更好的牛马,哎,退伍没有包分配你真的亏了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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