185. 部门工资前三高的所有员工 + 多表联合 + join + dense_rank()
185. 部门工资前三高的所有员工
LeetCode_MySql_185
题目描述

方法一:使用join on
# Write your MySQL query statement below
select d.Name as 'Department', e1.Name as 'Employee', Salary
from Employee e1 join Department d on e1.DepartmentId = d.Id
where
3 >( # 查找工资高于e1.Salary的个数
select count(distinct Salary)
from Employee e2
where e1.DepartmentId = e2.DepartmentId
and e1.Salary < e2.Salary
);
方法二:使用dense_rank() over
# Write your MySQL query statement below
/**
解题思路:先对Employee表进行部门分组工资排名,再关联Department表查询部门名称,再使用WHERE筛选出排名小于等于3的数据(也就是每个部门排名前3的工资)。
**/
select b.Name as Department, e2.Name as Employee, e2.Salary
from
Department b join
(
select DepartmentId, Name, Salary, dense_rank() over(partition by DepartmentId order by Salary desc) as rankId
from Employee
) as e2
on e2.DepartmentId = b.Id
where e2.rankId <= 3;
185. 部门工资前三高的所有员工 + 多表联合 + join + dense_rank()的更多相关文章
- Leetcode的SQL题解:185. 部门工资前三高的员工
题目 查询部门工资前三高的员工. 我用的数据库是oracle. 下面是数据表的信息. Employee表数据: | ID | NAME | Salary | DepartmentId | | -- | ...
- 部门工资前三高的所有员工 - LeetCode
Employee 表包含所有员工信息,每个员工有其对应的工号 Id,姓名 Name,工资 Salary 和部门编号 DepartmentId . +----+-------+--------+---- ...
- [SQL]LeetCode185. 部门工资前三高的员工 | Department Top Three Salaries
SQL 架构 Create table If Not Exists Employee (Id ), Salary int, DepartmentId int) Create table If Not ...
- sql查询:部门工资前三高的员工和部门工资最高的员工
创建表:Create table If Not Exists Employee (Id int, Name varchar(255), Salary int, DepartmentId int);Cr ...
- SQL查询每个部门工资前三名的员工信息
--通用sql select deptno, ename, sal from emp e1 where ( ) from emp e2 where e2.deptno=e1.deptno and e2 ...
- mysql查询每个部门/班级前几名
Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id . +----+-------+--------+--------------+ | I ...
- [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- leetcode 184 部门工资最高的员工
题目描述:Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id. Department 表包含公司所有部门的信息. 编写一个 SQL 查询,找 ...
- mysql查询之部门工资最高的员工
最近发现一个网站 力扣 查看 上面有很多算法和数据库的题目,做了一下,发现自己平时都疏忽了,因此边做边记录下来 Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 de ...
随机推荐
- Educational Codeforces Round 102 (Rated for Div. 2) D. Program (思维,前缀和)
题意:给你一个只含\(+\)和\(-\)的字符串,给你一个数\(x\),\(x\)初始为\(0\),随着字符串的遍历会加一减一,现在有\(m\)个询问,每个询问给出一个区间\([l,r]\)表示将这个 ...
- Codeforces Round #296 (Div. 2B. Error Correct System
Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta ...
- 01背包记录路径 (例题 L3-001 凑零钱 (30分))
题意: 就是找出来一个字典序最小的硬币集合,且这个硬币集合里面所有硬币的值的和等于题目中的M 题解: 01背包加一下记录路径,如果1硬币不止一个,那我们也不采用多重背包的方式,把每一个1硬币当成一个独 ...
- 前端接收后端文件流导出excel文档遇到的问题
先上代码: Vue.prototype.download = function(oUrl, filename) { this.axios .get(oUrl, { responseType: 'arr ...
- msfconsole web后门
一.PHP后门 在meterpreter中有一个名为PHP meterpreter的payload,利用这个可以成功反弹.步骤如下: 1. 使用msfvenom 创建一个webshell.php 2. ...
- 基金术语 All In One
基金术语 All In One GP.LP.PE.VC.FOF LP 有限合伙人(Limited Partner, LP):我们可以简单的理解为出资人. 很多时候,一个项目需要投资上千万乃至数个亿的资 ...
- Vue & Sentry sourcemaps All In One
Vue & Sentry sourcemaps All In One vue & sentry & sourcemaps https://docs.sentry.io/plat ...
- 如何关闭 iPad Pro 自动开启 wifi 和蓝牙
如何关闭 iPad Pro 自动开启 wifi 和蓝牙 为了省电,明明关闭了,但是发现每天都会自动开启,什么鬼设计 https://support.apple.com/zh-cn/HT208086 h ...
- html5 & iOS
html5 & iOS Apple App Store审核指南 https://developer.apple.com/app-store/review/guidelines/ Apple审核 ...
- text image & 思维脑图 & xmind
text image & 思维脑图 text-image 图片读 rgb 值->灰度值->字符; rgb->灰度值的公式 google 一下就有,灰度值传字符部分,从灰度值从 ...