LEETCODE 181. 超过经理收入的员工

  1. 超过经理收入的员工
    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的表头

  2. 查找重复的电子邮箱
    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题同样的写法

  3. 从不订购的客户
    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为空

  4. 部门工资最高的员工
    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表中选择这项的类名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值