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 ...
随机推荐
- 成功安装mysql后,为何服务管理器里找不到MYSQL服务名【转】
解决方案:(参考以下命令) 1.打开cmd,切换到mysql的bin目录下 2. D:\Program Files\MySQL5.1\bin>mysqld.exe -install Servic ...
- golang数据结构和算法之StackArray数组堆栈
用数组实现的堆栈, 另一种,是用链表实现的堆栈, 在各种不同的编程语言上, 实现都是类似的. StackArray.go package StackArray //基于数组实现的堆栈 const ar ...
- 非ssl给163发邮件,报错,无解ing
#给163发送邮件import smtplibfrom email.mime.text import MIMETextnam='15527721040@163.com'send='1552772104 ...
- (转)新建maven项目时报错Error:Maven Resources Compiler: Maven project configuration required for module 'XX'解决方法
转载地址:https://blog.csdn.net/qq784515681/article/details/85070195 在新建maven项目时,Problems中报错: Error:Maven ...
- Drop_out--防止过拟合
With probability keep_prob, outputs the input element scaled up by 1 / keep_prob, otherwise outputs ...
- SpringMVC详细流程(一)
Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求-响应模 ...
- php 学习笔记之搭建开发环境(mac版)
Mac 系统默认集成了很多开发工具,其中就包括 php 所需要的一些软件工具. 下面我们将搭建最简单的 php 开发环境,每一步都会验证上一步的操作结构,请一步一步跟我一起搭建吧! web 服务器之 ...
- C#中List<T>转DataTable
通过查询出来的类的集合的属性集合生成数据行,并通过属性获取每一个实体的指定属性的指定值
- 小白专场-堆中的路径-c语言实现
目录 一.题意理解 二.堆的表示及其操作 三.主程序 更新.更全的<数据结构与算法>的更新网站,更有python.go.人工智能教学等着你:https://www.cnblogs.com/ ...
- select使用css居右对齐
select{ direction: rtl; } 下面的方法无效 select{ text-align: right; }