MySQL 实践题目
约 256 字小于 1 分钟
2025-05-27
175. 组合两个表
-- 组合两个表
# 左连接以左表为基础,将右表中满足连接条件的记录与左表进行匹配,并保留左表中所有的记录,无论右表中是否有匹配
# 如果右表中没有与左表匹配的记录,则在结果中对应的右表列显示为 NULL
select FirstName, LastName, City, State
from Person left join Address
on Person.PersonId = Address.PersonId;
176. 第二高的薪水
-- 第二高的薪水
select max(salary) as SecondHighestSalary # 将排去所有最大值剩下的数种选择新的最大值
from Employee
where salary < (select max(salary) from Employee) # 先查询出表中最大的那个值, 筛选出比该值小的所有数
1068. 产品销售分析 I
-- 产品销售分析 I
select product_name, year, price from Sales join Product using(product_id);
# 或者使用 select product_name, year, price from Sales, Product where Sales.product_id=Product.product_id; 也是一样的