您的位置:首页 > 其它

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

2020-02-03 02:31 113 查看
  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表中选择这项的类名

  • 点赞
  • 收藏
  • 分享
  • 文章举报
天上掉大神 发布了2 篇原创文章 · 获赞 0 · 访问量 25 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: