方法)外部连结+子查询
SELECT g.* FROM grade AS g LEFT JOIN ( SELECT job, AVG(score)avg_score -- 求出各职位平均分 FROM grade GROUP BY job)a ON g.job = a.job -- 同一职位 WHERE g.score > a.avg_score -- 分数大于平均分 ORDER BY g.id ASC;
方法)外部连结+子查询
SELECT g.* FROM grade AS g LEFT JOIN ( SELECT job, AVG(score)avg_score -- 求出各职位平均分 FROM grade GROUP BY job)a ON g.job = a.job -- 同一职位 WHERE g.score > a.avg_score -- 分数大于平均分 ORDER BY g.id ASC;