select t1.id,t1.job,t1.score from grade t1 left join (select job,avg(score) avg from grade group by job) t2 on t1.job=t2.job where t1.score>t2.avg order by t1.id asc 提醒自己:使用子表连接的时候一定注意查询字段的选取,如果主句查询的是*就会输出两个表的所有字段,不要偷懒不写t1.id,t1.job,t1.score。
select t1.id,t1.job,t1.score from grade t1 left join (select job,avg(score) avg from grade group by job) t2 on t1.job=t2.job where t1.score>t2.avg order by t1.id asc 提醒自己:使用子表连接的时候一定注意查询字段的选取,如果主句查询的是*就会输出两个表的所有字段,不要偷懒不写t1.id,t1.job,t1.score。