题目:
综合练习
SELECT last_name,salary
FROM employees
WHERE department_id =
(SELECT department_idFROM employeesWHERE last_name = 'Zlotkey'
);
SELECT employee_id,last_name,salary
FROM employees
WHERE salary >
(SELECT AVG(salary)FROM employees
);
SELECT last_name,job_id,salary
FROM employees
WHERE salary > ALL
(SELECT salaryFROM employeesWHERE job_id = 'SA_MAN'
);
SELECT employee_id,last_name
FROM employees
WHERE department_id = ANY
(SELECT DISTINCT department_idFROM employees WHERE last_name LIKE '%u%'
);
SELECT employee_id
FROM employees
WHERE department_id IN
(SELECT department_idFROM departmentsWHERE location_id = 1700
);
SELECT e.last_name,e.salary,m.last_name
FROM employees e, employees m
WHERE e.manager_id = m.employee_id
AND m.last_name = 'king';SELECT last_name,salary,last_name
FROM employees
WHERE last_name IN
(SELECT last_nameFROM employeesWHERE last_name = 'king'
);
SELECT last_name,salary
FROM employees
WHERE salary <= ALL
(SELECT salaryFROM employees
);SELECT last_name,salary
FROM employees
WHERE salary =
(SELECT MIN(salary)FROM employees
);
SELECT *
FROM departments d1 , (SELECT AVG(salary) avg_sal,department_idFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 0,1) d2
WHERE d1.department_id = d2.department_id;
SELECT d1.*,d2.department_id,d2.avg_sal
FROM departments d1 , (SELECT AVG(salary) avg_sal,department_idFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 0,1) d2
WHERE d1.department_id = d2.department_id;
SELECT j.*,e.avg_sal
FROM jobs j,(SELECT AVG(salary) avg_sal,job_idFROM employeesGROUP BY job_idORDER BY avg_sal DESCLIMIT 0,1) e
WHERE j.job_id = e.job_id;
SELECT department_id
FROM employees
WHERE department_id IS NOT NULL
GROUP BY department_id
HAVING AVG(salary) > (SELECT AVG(salary)FROM employees
);
SELECT DISTINCT m.*
FROM employees e,employees m
WHERE e.manager_id = m.employee_id
SELECT e1.department_id,e2.max_sal
FROM employees e1 , (SELECT MAX(salary) max_sal,department_idFROM employees e2 GROUP BY department_idORDER BY max_sal LIMIT 0,1
)e2
WHERE e1.department_id = e2.department_id;
SELECT employee_id, last_name,m.department_id,email,salary
FROM employees e , (SELECT AVG(salary) avg_sal,department_idFROM employees m GROUP BY department_id,employee_idORDER BY avg_sal DESCLIMIT 0,1
) m
WHERE e.department_id = m.department_id
LIMIT 0,1;
SELECT department_id
FROM departments
WHERE department_id NOT IN
(SELECT DISTINCT department_idFROM employeesWHERE job_id = 'ST_CLERK'
);
SELECT last_name
FROM employees e1
WHERE NOT EXISTS
(SELECT *FROM employees e2 WHERE e1.manager_id = e2.employee_id
);
SELECT e.employee_id,e.last_name,e.hire_date,e.salary
FROM employees e JOIN employees m
WHERE e.manager_id = m.employee_id
AND m.last_name = 'De Haan';
SELECT employee_id,last_name,salary
FROM employees e1
WHERE salary >
(SELECT AVG(salary)FROM employees e2WHERE e1.department_id = e2.department_id
);
SELECT department_name,department_id
FROM departments d
WHERE 5 <
(SELECT COUNT(*)FROM employees eWHERE d.department_id = e.department_id
);
SELECT country_id
FROM locations l
WHERE 2 <
(SELECT COUNT(*)FROM departments d WHERE l.location_id = d.location_id
);