您当前的位置: 首页 >  leetcode

孑渡

暂无认证

  • 3浏览

    0关注

    178博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Leetcode】简单题:超过经理收入的员工

孑渡 发布时间:2022-04-15 14:14:52 ,浏览量:3

超过经理收入的员工

SQL架构:

Create 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', 'None')
insert into Employee (id, name, salary, managerId) values ('4', 'Max', '90000', 'None')

±------------±--------+ | Column Name | Type | ±------------±--------+ | id | int | | name | varchar | | salary | int | | managerId | int | ±------------±--------+ Id是该表的主键。 该表的每一行都表示雇员的ID、姓名、工资和经理的ID。 编写一个SQL查询来查找收入比经理高的员工。 以 任意顺序 返回结果表。 查询结果格式如下所示。 来源:力扣(LeetCode)

AC代码
select a.name as Employee from Employee as a, Employee as b
where a.managerId = b.id and a.salary > b.salary
官方代码
SELECT
    *
FROM
    Employee AS a,
    Employee AS b
WHERE
    a.ManagerId = b.Id
        AND a.Salary > b.Salary
;
# 作者:LeetCode

算是简单的复习SQL数据库语言了

关注
打赏
1663211900
查看更多评论
立即登录/注册

微信扫码登录

0.0376s