SQL热题272解法

解法一:使用窗口函数

select id, job, score from

(

    select id, job, score, avg(score)over(partition by job)avg from grade

)t

where t.score > t.avg

解法二:不使用窗口函数,先用临时表得到平均分,再与原表进行连接

select g.* from grade as g join

(

select job, avg(score)avg_score from grade

group by job

)t

on g.job = t.job

where g.score > t.avg_score

order by id ASC

#笔试#
全部评论
感觉还是使用窗口函数简单些呀
1 回复 分享
发布于 03-15 16:38 上海

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务