题解 | #考试分数(二)#
考试分数(二)
http://www.nowcoder.com/practice/f456dedf88a64f169aadd648491a27c1
select id,job,score
from grade g1
where score>(select avg(score)as avg
from grade g2
where g1.job=g2.job
group by g2.job)
order by id;
#一.计算各job的平均得分 select avg(score)as avg from grade g2 group by g2.job 二.用关联子查询取出各job的分数大于平均值的行 select id,job,score from grade g1 where score>(select avg(score)as avg from grade g2 where g1.job=g2.job group by g2.job) order by id; *这里注意关联条件g1.job=g2.job写在子查询里,该条件的意思是:在同一job种类下对各分数和平均分数进行比较。