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 | 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 |
+----------+
这种单表比较条件,一般都是表内进行join
操作.
参照此思路,解题如下所示:
# Write your MySQL query statement below
SELECT
a.Name AS Employee
FROM Employee a, Employee b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary;
运行效率在可以接受的范围,此外语句也较为清晰便于维护.
LeetCode——Employees Earning More Than Their Managers的更多相关文章
- [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- LeetCode - Employees Earning More Than Their Managers
Description: The Employee table holds all employees including their managers. Every employee has an ...
- Leetcode 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- leetcode 181 Employees Earning More Than Their Managers 不会分析的数据库复杂度
https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ 老师上课没分析这些的复杂度, ...
- LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)
题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id 等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...
- LeetCode SQL:Employees Earning More Than Their Managers
# Write your MySQL query statement below SELECT a.Name FROM Employee AS a INNER JOIN Employee AS b O ...
- [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers
SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...
- LeeCode(Database)-Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- 【SQL】181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
随机推荐
- 《Python自动化测试九章经》
Python是当前非常流行的一门编程语言,它除了在人工智能.数据处理.Web开发.网络爬虫等领域得到广泛使用之外,他也非常适合软件测试人员使用,但是,对于刚入行的测试小白来说,并不知道学习Python ...
- MySQL通过SHOW TABLE STATUS查看库中所有表的具体信息
有时候我们想看下指定库下所有表的使用情况,比如,查询表的Table大小,什么时候创建的,数据最近被更新的时间(即最近一笔insert/update/delete的时间).这些信息对我们进行库表维护很有 ...
- arm-linux-gcc-5.4.0安装方法
首先需要下载arm-linux-gcc的安装包 这里提供一个5.4.0版本的安装包,如有需要自行下载. 下载链接:https://pan.baidu.com/s/1prpdmVNWBFzg79OXQs ...
- C语言中变量和函数的作用域和链接属性
C语言中变量和函数的作用域和链接属性 作用域 代码块作用域: 代码块指的是使用"{}"包围起来的部分. 在代码块中定义的变量,代码块之外是不能访问的. 代码块嵌套之后的变量作用域, ...
- 【bzoj2648】SJY摆棋子(kdtree)
传送门 题意: 二维平面上有若干个点. 现在要维护一种数据结构,支持插入一个点以及询问其余点到某个点的最小曼哈顿距离. 思路: 这是个\(kdtree\)模板题. \(kdtree\)是一种可以高效处 ...
- Html学习之十二(CSS选择器的应用二)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- CentOS7 安装 anaconda
Anaconda是一个开源的Python发行版本,可以帮助我们更方便地配置Python环境. 如果只需要某些包,或者需要节省带宽或存储空间,也可以使用Miniconda这个较小的发行版 0. 开始前 ...
- VS2017项目升级 error LNK2005: "public: __thiscall ATL::CTime::
我是将项目升级到从VS2012 升级VS2017, 报错如下 1>atlsd.lib(atltime.obj) : error LNK2005: "public: __thiscall ...
- eclipse 离线安装SVN插件(支持eclipse201909)
1.情景展示 重装eclipse后,按照网上的在线安装方法,SVN始终安装失败,之前的离线SVN包也不能用. 2.解决方案 SVN离线包下载地址:http://subclipse.tigris.o ...
- [LeetCode#178]Rank Scores
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...