将子查询结果充当一张表,要求必须起别名
#查询每个部门的平均工资的工资等级 #第一步: SELECT AVG(salary),department_id FROM employees GROUP BY department_id SELECT * FROM job_grades; #第二步:连接第一步的结果集和job_grades表,筛选条件平均工资 #将结果集充当成一张表,这张表需要起别名 SELECT ag_dep.*,g.'grade_level' FROM ( SELECT AVG(salary) ag,department_id FROM employees GROUP BY department_id ) ag_dep INNER JOIN job_grades g ON ag_dep.ag BETWEEN lowest_sal AND highest_sal;
标签:ag,后面,查询,grades,MySQL,department,id,SELECT From: https://www.cnblogs.com/yzhone/p/16863223.html