[ 方式一]
select employee_id,manager_id,department_id
from employees
where manager_id in
(select manager_id
from employees
where employee_id in (174,141))
and
department_id in (
select department_id
from employees
where employee_id in (174,141))
and
employee_id notin(174,141);
[ 方式二]
select employee_id,manager_id,department_id
from employees
where(manager_id,department_id)
in
(
select manager_id,department_id
from employees
where employee_id in (141,174))
and
employee_id notin (174,141);
的 返回比本部门平均工资高的员工的 last_name, department_id,
salary
SELECT a.last_name, a.salary,
a.department_id, b.salavg
FROM employees a,
(SELECT department_id,
AVG(salary) salavg
FROM employees
GROUPBY department_id) b
WHERE a.department_id = b.department_id
AND a.salary > b.salavg;
SELECT employee_id, last_name,
(CASE department_id
WHEN (SELECT department_id FROM departments
WHERE location_id = 1800)
THEN'Canada'ELSE'USA'END) location
FROM employees;