-
超过经理收入的员工
select e1.Name as Employee from Employee as e1 ,Employee as e2 where e1.ManagerId=e2.Id AND e1.Salary>e2.Salary
***as Employee***指使用 Employee作为搜索出的e1.Name的表头 -
查找重复的电子邮箱
SELECT DISTINCT a.Email as Email FROM Person a, Person b WHERE a.Email = b.Email AND a.Id != b.Id
***DISTINCT***的作用是去搜索结果的去重
SELECT DISTINCT a.Email as Email FROM Person as a, Person as b WHERE a.Email = b.Email AND a.Id != b.Id
是和181题同样的写法 -
从不订购的客户
select Name as Customers from Customers left join Orders on Customers.Id = Orders.CustomerId where Orders.CustomerId is NULL
***left join***左连接表明所输出的类在左侧
is NULL 是在有表中Orders.CustomerId为空 -
部门工资最高的员工
select b.Name as Department,a.Name as Employee,a.Salary as Salary from Employee as a,Department as b where a.DepartmentId=b.Id and (a.DepartmentId,a.Salary) in (select DepartmentId,max(Salary) from Employee group by DepartmentId)
b.Name as Department,a.Name as Employee,a.Salary as Salary为select 内容的并列写法
where a.DepartmentId=b.Id为第一个限制条件表明同时在两个表的连接关系
(select DepartmentId,max(Salary) from Employee group by DepartmentId) 为在通过 DepartmentId 分类后,在每类中选择 DepartmentId,max(Salary)
(a.DepartmentId,a.Salary) in (select DepartmentId,max(Salary) 为在a表中选择这项的类名
LEETCODE 181. 超过经理收入的员工
最新推荐文章于 2023-06-03 01:08:48 发布