#案例:查询每个部门的平均工资的工资等级
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`;
#案例:查询每个部门的平均工资的工资等级
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`;