第一题:超过经理收入的员工
解法一:
select a.Name as Employee from
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary
;
解法二:
select Name as Employee
from Employee as a
where Salary>(select Salary
from Employee
where id=a.managerid
)
第二题:从不订购的客户
select c.Name as Customers
from Customers c left join Orders o
on c.Id =o.CustomerId
where o.Id is null;
题目三:查找重复的电子邮箱
解法一:
select distinct(p1.Email)
from Person p1
join Person p2
on p1.Email = p2.Email
and p1.id!=p2.id;
解法二:
select Email from Person
group by Email having count(email)>1;