数据库刷题

数据库刷题(leetcode)

考虑到可能不是每个人都有地址信息,我们应该使用 outer join 而不是默认的 inner join
注意:如果没有某个人的地址信息,使用 where 子句过滤记录将失败,因为它不会显示姓名信息。

select FirstName, LastName, City, State
from Person left join Address
on Person.PersonId = Address.PersonId;

在这里插入图片描述
在这里插入图片描述
2.
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary)

select max(salary) SecondHighestSalary from Employee
where salary  not in ( select max(Salary) from Employee);(方法不好)

3.查询重复的电子邮件

select Email from
(
  select Email, count(Email) as num
  from Person
  group by Email
) as statistic
where num > 1
;

发布了79 篇原创文章 · 获赞 44 · 访问量 2023

猜你喜欢

转载自blog.csdn.net/wy19961103/article/details/105170451