SELECT employee_id, manager_id, department_id FROM employees WHERE manager_id IN ( SELECT manager_id FROM employees WHERE employee_id IN (141, 174) ) AND department_id IN ( SELECT department_id FROM employees WHERE employee_id IN (141, 174) ) AND employee_id NOTIN (141, 174);
5. 查询最低工资大于50号部门最低工资的部门id和其最低工资
1 2 3 4 5 6 7 8 9
SELECT department_id, MIN(salary) FROM employees GROUPBY department_id HAVINGMIN(salary) > ( -- 50号部门最低工资 SELECTMIN(salary) FROM employees WHERE department_id =50 );
SELECT employee_id, last_name, job_id,salary FROM employees WHERE salary <ANY ( -- job_id 为'IT_PROG'部门的工资 SELECT salary FROM employees WHERE job_id ='IT_PROG' ) AND job_id <>'IT_PROG';
SELECT employee_id, last_name, job_id,salary FROM employees WHERE salary <ALL ( -- job_id 为'IT_PROG'部门的工资 SELECT salary FROM employees WHERE job_id ='IT_PROG' ) AND job_id <>'IT_PROG';
3. 查询平均工资最低的部门id
1 2 3 4 5 6 7 8 9 10 11 12 13
SELECT department_id FROM employees GROUPBY department_id HAVINGAVG(salary) = ( -- 最低平均工资 SELECTMIN(avg_sal) FROM ( -- 按部门分组,求各部门平均工资 SELECTAVG(salary) avg_sal FROM employees GROUPBY department_id ) dept_avg_sal )