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 回复 分享
发布于 2025-03-15 16:38 上海

相关推荐

01-03 12:06
复旦大学 Java
点赞 评论 收藏
分享
2025-12-14 11:43
黑龙江大学 Java
用微笑面对困难:确实比较烂,可以这么修改:加上大学的qs排名,然后大学简介要写一些,然后硕士大学加大加粗,科研经历第一句话都写上在复旦大学时,主要负责xxxx,简历左上角把学校logo写上,建议用复旦大学的简历模板
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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