mysql from后接子查询,实际为将结果集合并成一张表
#案例:查询每个部门的平均工资的工资等级
SELECT av.*,g.`grade_level`
FROM (
SELECT AVG(salary) ag,department_id
FROM employees
GROUP BY department_id
) av
INNER JOIN job_grades g
ON av.ag BETWEEN g.`lowest_sal` AND g.`highest_sal`;