[LeetCode] 181.超过经理收入的员工
Employee表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
给定Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。
+----------+
| Employee |
+----------+
| Joe |
+----------+
题解:
方法一:查出两个表(都是Employee表),分别As为a,b
SELECT
*
FROM
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary
方法二:使用JOIN将两个表(同一个表)连接起来,使用on指定条件(a.ManagerId = b.Id)
SELECT
a.NAME AS Employee
FROM Employee AS a JOIN Employee AS b
ON a.ManagerId = b.Id
AND a.Salary > b.Salary
[LeetCode] 181.超过经理收入的员工的更多相关文章
- 181. 超过经理收入的员工 + join + MySql
181. 超过经理收入的员工 LeetCode_MySql_181 题目描述 方法一:笛卡尔积 # Write your MySQL query statement below select e1.N ...
- LeetCode:181.超过经理收入的员工
题目链接:https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/ 题目 Employee 表包含所有员 ...
- sql 181. 超过经理收入的员工
Employee 表包含所有员工,他们的经理也属于员工.每个员工都有一个 Id,此外还有一列对应员工的经理的 Id. +----+-------+--------+-----------+| Id | ...
- LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)
题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id 等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...
- [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers
SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...
- 超过经理收入的员工 表的自JOIN
https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/description/ The Employe ...
- leetcode 184 部门工资最高的员工
题目描述:Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id. Department 表包含公司所有部门的信息. 编写一个 SQL 查询,找 ...
- 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
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
随机推荐
- git-vi
VI命令可以说是Unix/Linux世界里最常用的编辑文件的命令了,但是它的命令集太多,所以要想精通他,也是一件很不容易的事情,除了专业SA,对于我们开发人员而已只需要掌握一些最最常见的用法应该就可以 ...
- sql插入语句笔记
使用INSERT插入数据行 [一次插入一行数据] 全写: INSERT INTO renshi (name, sex, age ,tel) VALUES ('胡大姐','女','35','13 ...
- @RestController vs @Controller
package com.example.demo.controller; import java.util.HashMap; import java.util.Map; import org.spri ...
- [C++] 所有该类的对象共享静态类成员变量
问:智能指针可以对指针的引用数量进行计数,一个智能指针释放时,别的智能指针怎么知道的? 同一类的对象共享同一变量最简单的方法是静态变量: 不像普通的变量,静态成员变量是被所有类对象共享的,不同的对象可 ...
- txt_to_csv
import csv def txt2csv(inf, outf): with open(inf,'r') as fin, open(outf,'w',newline='') as fout: wrt ...
- 唐太宗灵州勒石 TANGTAIZONGLINZHOULESHI
唐太宗灵州勒石 唐贞观二十年(646年),在唐军和回纥部落联合打败突厥薛延陀部后,原归附薛延陀部的回纥.拔野古.斛薛等部族,越过贺兰山,进入了今宁夏的银川.吴忠一带地区.这些总族向唐朝提出,愿意臣服唐 ...
- python输出转义字符
转义字符在字符串中不代表自己,比如\n代表回车,不代表\n字符,那我想输入转义字符本身呢? 答:在字符串前面加个r 如print(“aa\nbb”) 会输出aa bb 如print(r"aa ...
- centos 6.5 查看 IP
ip 和 ifconfig 两个命令都可以,但现在推荐使用 ip ip addr ifconfig
- Delphi Win API 函数 [ ShellAPI ] ShellExecute 函数
引用单元:uses ShellAPI; 函数原型:function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,Directory ...
- webpackES6语法转ES5语法
安装babel-loader: npm install --save-dev babel-loader@7 babel-core babel-preset-es2015 webpack.config. ...