思路:聚合函数和表连接的使用
方法一:利用 score > avg(score),因为where条件中不能使用聚合函数,所以我们在where条件中直接写查询,查询出avg(score)
完整代码:
select *
from grade
where score > (select avg(score) from grade g1 where g1.job = grade.job)
order by id
方法二:求出平均分数的表与原表连接 完整代码:
select g.*
from grade as g join (select job, avg(score) as score_avg from grade group by job) as s
on g.job = s.job
where g.score > s.score_avg
order by id