目录
一、组合两个表
1、题目描述
2、题解
3、源码
select FirstName,LastName,City,State from Person left join Address on Person.PersonId=Address.PersonId;
二、超过经理收入的员工
1、题目描述
2、题解
3、源码
select
e1.Name AS Employee
from
Employee as e1,
Employee as e2
where
e1.ManagerId = e2.Id AND e1.Salary>e2.Salary
三、查找重复的电子邮箱
1、题目描述
2、题解
3、源码
方法一:
# select
# Email
# from
# Person
# group by
# Email
# having
# count(Email) > 1;
方法二:
select Email from
(
select Email, count(Email) as num
from Person
group by Email
) as statistic
where num > 1
;
四、从不订购的客户
1、题目描述
2、题解
3、源码
# Write your MySQL query
select
Name as Customers
from
Customers
where
Customers.id not in
(
select customerid from orders
);
五、删除重复的电子邮箱
1、题目描述
2、题解
3、源码
# Write your MySQL query statement below
DELETE p1 FROM Person p1,
Person p2
WHERE
p1.Email = p2.Email AND p1.Id > p2.Id