分数大于其所在工作(job)分数的平均分的所有grade属性

考试分数(二)

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

/*1、并表
select 
    id,
    job,
    score
from grade
left join (select job,avg(score) avg from grade group by job) t
using(job)
where score>avg
order by id

2、where子查询
select t.id,t.job,t.score
from grade t
where score>(select avg(score) from grade t1
             where t.job=t1.job
             group by t1.job)
order by t.id

3、窗口函数:where语句需写在外层查询中,写在内层查询会报错。
*/
select t.id,t.job,t.score
from (
    select 
        *,
        avg(score) over(partition by job) avg
    from grade
    ) t
where t.score>t.avg
order by t.id



全部评论

相关推荐

纯真的河老师在喝茶:第一个是这个时间点岗位少,第二个是这个简历重复度太高了,10个有9个简历差不多的
点赞 评论 收藏
分享
昨天 16:26
已编辑
河北科技学院 Java
勇敢的牛油不服输:2800-300那不等于2500一个月吗兄弟们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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