-- 3
SELECT AVG(salary) FROM employees GROUP BY department_id;
SELECT employee_id, last_name, salary, e.`department_id`
FROM employees AS e
INNER JOIN (
SELECT AVG(salary) AS ag, department_id
FROM employees
GROUP BY department_id
) AS ag_dep
ON e.`department_id` = ag_dep.department_id
WHERE salary > ag_dep.ag;
-- 4
SELECT employee_id,CONCAT(first_name,last_name)
FROM employees AS e
INNER JOIN (
SELECT department_id
FROM employees
WHERE CONCAT(first_name,last_name) LIKE 'u%' OR CONCAT(first_name,last_name) LIKE '%u' OR CONCAT(first_name,last_name) LIKE '%u%'
GROUP BY department_id
) AS b
ON e.department_id=b.department_id;
-- 5
SELECT employee_id
FROM employees
WHERE department_id
IN(
SELECT department_id
FROM departments
WHERE location_id=1700
);
-- 6
SELECT last_name, salary
FROM employees
WHERE manager_id
IN(
SELECT employee_id
FROM employees
WHERE last_name = "K_ing"
);
-- 7
SELECT CONCAT(first_name, '.' ,last_name) "姓.名"
FROM employees
WHERE salary = (
SELECT MAX(salary) FROM employees
);