# 工资高于abel的人
select name, salary from employees where salary >
(select salary from employees where name='abel');
内部子查询仅仅执行一次, 故为不相关;
# 由内而外解析
# 50号 部门最低工资
select min(salary) from employees where depart_id=50;
# 查询最低工资大于()的部门的id和最低工资
select depart_id, min(salary) from employees group by depart_id having min(salary) > ();
# 将以上子查询放入()中即可;
select employee_id, name, (case depart_id when (select depart_id from employees where loc_id=190) then 'A'
else 'B' end) as location
from employees;
# 薪资小于任何一个结果
select xxx from employees where salary < any(多行子查询);
# 查询 平均工资 最低的部门
select depart_id, min(avg_salary) from (select depart_id, avg(salary) as avg_salary from employees group by depart_id) as tt;
select depart_id from employees group by depart_id having avg(salary) <= all(select avg(salary) as avg_salary from employees group by depart_id)
更多【mysql-mysql基础 --子查询】相关视频教程:www.yxfzedu.com