MySQL之select和from后面的子查询
select 后面(很少用的,可以用前面讲的方法实现)
案例:
select d.*,(
select d.department_name count(*) from employees e
where d.department_id=e.department_id
) from departments d;
from后面的子查询:
案例:查询每个部门的平均工资等级
select avg(salary),department_id from employees group by department_id;
SELECT
avg_res.avgs,avg_res.`department_id`,g.`grade_level`
FROM
(
SELECT AVG(salary) avgs,department_id
FROM employees GROUP BY department_id
) avg_res
,`job_grades` g
WHERE
avg_res.avgs BETWEEN g.`lowest_sal` AND g.`highest_sal`;
原文地址:https://blog.csdn.net/weixin_43227851/article/details/144298560
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!