1 Star 0 Fork 0

wd6/LeetCode-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
employees-earning-more-than-their-managers.sql 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
# Time: O(n^2)
# Space: O(1)
#
# 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 |
# +----------+
#
# Time: O(n^2)
# Space: O(n)
# Write your MySQL query statement below
SELECT e.Name AS Employee FROM Employee e LEFT JOIN Employee b
ON e.ManagerId=b.Id
WHERE e.Salary > b.Salary
# Time: O(n^2)
# Space: O(1)
# Write your MySQL query statement below
SELECT Name AS Employee
FROM Employee e
WHERE e.ManagerId IS NOT NULL AND e.Salary > (SELECT Salary
FROM Employee
WHERE e.ManagerId = Id)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wd6/LeetCode-1.git
git@gitee.com:wd6/LeetCode-1.git
wd6
LeetCode-1
LeetCode-1
master

搜索帮助