leetcode181 超过经理收入的员工 Employees Earning More Than Their Managers

Employee表包含所有员工,包括他们的经理。每个员工都有一个 Id,此外还有一列对应的经理Id。

创建表和数据:

drop table EmployeeCreate table If Not Exists Employee (Id int, Name varchar(255), Salary int, ManagerId int);
Truncate table Employee;
insert into Employee (Id, Name, Salary,ManagerId) values (‘1‘, ‘Joe‘, ‘70000‘, ‘3‘);
insert into Employee (Id, Name, Salary,ManagerId) values (‘2‘, ‘Henry‘, ‘80000‘, ‘4‘);
insert into Employee (Id, Name, Salary,ManagerId) values (‘3‘, ‘Sam‘, ‘60000‘, Null);
insert into Employee (Id, Name, Salary,ManagerId) values (‘4‘, ‘Max‘, ‘90000‘, Null);

解法:

1.通过表的自连接,找出每个员工的经理,筛选出薪水比经理薪水高的员工。

select E1.Name as Employee
from Employee as E1 join Employee as E2 on (E1.ManagerId  = E2.Id and E1.salary > E2.salary)

原文地址:https://www.cnblogs.com/forever-fortunate/p/11722830.html

时间: 2024-11-05 19:33:54

leetcode181 超过经理收入的员工 Employees Earning More Than Their Managers的相关文章

[SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers

SQL架构 1 Create table If Not Exists Employee (Id int, Name varchar(255), Salary int, ManagerId int) 2 Truncate table Employee 3 insert into Employee (Id, Name, Salary, ManagerId) values ('1', 'Joe', '70000', '3') 4 insert into Employee (Id, Name, Sala

181. 超过经理收入的员工

Employee 表包含所有员工,他们的经理也属于员工.每个员工都有一个 Id,此外还有一列对应员工的经理的 Id. +----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | M

超过经理收入的员工

Employee 表包含所有员工,他们的经理也属于员工.每个员工都有一个 Id,此外还有一列对应员工的经理的 Id. +----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | M

力扣——超过经理收入的员工(数据库的题

Employee 表包含所有员工,他们的经理也属于员工.每个员工都有一个 Id,此外还有一列对应员工的经理的 Id. +----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | M

超过经理收入的员工(Sql语句)

SQL架构 Employee 表包含所有员工,他们的经理也属于员工.每个员工都有一个 Id,此外还有一列对应员工的经理的 Id. +----+-------+--------+-----------+ | Id | Name | Salary | ManagerId | +----+-------+--------+-----------+ | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | |

[LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多

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 |

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 | +----+-------+--------+--------

LeetCode - Employees Earning More Than Their Managers

Description: The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. Given the Employee table, write a SQL query that finds out employees who earn more than their manag

[LeetCode]Employees Earning More Than Their Managers,解题报告

目录 目录 题目 思路 AC SQL 题目 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 G