094-子查询练习
作者:互联网
SELECT `last_name`,`salary`
FROM `employees`
WHERE `department_id`=(
SELECT `department_id`
FROM `employees`
WHERE `last_name`='Zlotkey'
);
SELECT `employee_id`,`last_name`,`salary`
FROM `employees`
WHERE salary>(
SELECT AVG(e.salary)
FROM `employees` e
);
SELECT `last_name`,`salary`
FROM (
SELECT `department_id`,AVG(salary) avg_sal
FROM `employees`
GROUP BY `department_id`
)avg_list INNER JOIN `employees` e
ON avg_list.`department_id`=e.`department_id`
WHERE e.`salary`>avg_list.avg_sal;
SELECT `employee_id`,`last_name`
FROM `employees`
WHERE `department_id` IN(
SELECT DISTINCT `department_id`
FROM `employees`
WHERE `last_name` LIKE '%u%'
);
SELECT `last_name`,`employee_id`
FROM `employees` e
WHERE `department_id` IN(
SELECT DISTINCT `department_id`
FROM `departments`
WHERE `location_id`=1700
);
SELECT `last_name`,`salary`
FROM `employees`
WHERE `manager_id` IN(
SELECT `employee_id`
FROM `employees`
WHERE `last_name`='K_ing'
);
SELECT CONCAT(`first_name`,`last_name`) "姓.名"
FROM `employees`
WHERE salary=(
SELECT MAX(`salary`)
FROM `employees`
)
标签:name,employees,练习,094,查询,department,WHERE,id,SELECT 来源: https://blog.csdn.net/xiaoyuedake/article/details/113063710