DataBase -- Employees Earning More Than Their Managers My Submissions Question
Posted 江湖小妞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DataBase -- Employees Earning More Than Their Managers My Submissions Question相关的知识,希望对你有一定的参考价值。
Question:
The Employee
table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | Max | 90000 | NULL | +----+-------+--------+-----------+
Given the Employee
table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
+----------+ | Employee | +----------+ | Joe | +----------+
Analysis:
Employee表格包含公司里所有的员工,包括他们的经理。每个员工都有一个员工ID和一个经理ID。
给出Employee表格,写一个SQL语句,找出工资比他的经理还高的员工。例如在上面的例子中,只有Joe满足该情况。
最后给出什么则select后面接什么,如果遇到比较的,则应该选择使用两个表格。
Answer:
select e1.Name from Employee e1, Employee e2 where e2.Id = e1.ManagerId and e1.Salary > e2.Salary
以上是关于DataBase -- Employees Earning More Than Their Managers My Submissions Question的主要内容,如果未能解决你的问题,请参考以下文章
Oracle安装错误:File not found WFMLRSVCApp.ear
LeetCode:Database 90.使用唯一标识码替换员工ID