#行子查询(结果集:一行多列或多行多列)
#案例:查询员工编号最小并且工资最高的员工信息
#(1)查询最小的员工编号
SELECT MIN(`employee_id`) 最小员工编号
FROM `employees`;
#(2)查询最小员工编号的最高工资
SELECT MAX(`salary`)
FROM `employees`
WHERE `employee_id`;
#(3)查询员工信息
SELECT * FROM `employees`;
#(4)在(3)的基础上满足(1)和(2)
SELECT *
FROM `employees`
WHERE `employee_id`=(
SELECT MIN(`employee_id`)
FROM `employees`
)AND `salary`=(
SELECT MAX(`salary`)
FROM `employees`
);
#行子查询(两个判断条件用的符号都是等于,看上述解答)
SELECT *
FROM `employees`
WHERE (`employee_id`,`salary`) =
(
SELECT MIN(`employee_id`),MAX(`salary`)
FROM `employees`
);
行子查询
最新推荐文章于 2024-04-21 14:03:39 发布