1、查找重复的电子邮箱
编写一个 SQL 查询来报告所有重复的电子邮件。 请注意,可以保证电子邮件字段不为 NULL。以任意顺序返回结果表。
# 1、根据Email计数排序得到后 再筛选
select Email from
(select Email, count(Email) as num from Person group by Email)
as stastic
where num >1;
# 2、使用group by和having条件
select Email from Person
group by Email
having count(Email)>1;
2、组合两个表
# 连接两个表来获取一个人的地址信息
# outer join
select firstName, lastName, city, state
from Person left join Address
on Person.PersonId = Address.PersonId;