当前位置:网站首页>LeetCode: 184. 部门工资最高的员工
LeetCode: 184. 部门工资最高的员工
2022-07-22 09:11:00 【东西方集大成者】
原题:https://leetcode-cn.com/problems/department-highest-salary/
个人解法:
利 用 窗 口 函 数 : 利用窗口函数: 利用窗口函数:
select Department.Name as Department, e1.Name as Employee, e1.Salary
from (
select *
from (
select *, dense_rank() over(partition by DepartmentId order by Salary Desc) as ranking
from Employee
) as temp
where temp.ranking = 1
) as e1
left join Department
on e1.DepartmentId = Department.Id
where Department.Id IS NOT NULL;
注意Department表无任何数据的特殊情况,故需要判断Department.Id IS NOT NULL;
官方解法:
亮 点 : 两 个 字 段 一 起 I N 亮点: 两个字段一起IN 亮点:两个字段一起IN
SELECT
Department.name AS 'Department',
Employee.name AS 'Employee',
Salary
FROM
Employee
JOIN
Department ON Employee.DepartmentId = Department.Id
WHERE
(Employee.DepartmentId , Salary) IN
( SELECT
DepartmentId, MAX(Salary)
FROM
Employee
GROUP BY DepartmentId
)
;
边栏推荐
猜你喜欢
TCP与UDP及三次握手,四次挥手
【SDIO】SD2.0協議分析總結(三)-- SD卡相關命令介紹
Wechat official account web page authorization ----- redirect_ The URI domain name is inconsistent with the background configuration, and the error code is 10003
数据湖简单记录
枚举对象中属性
使用工厂的方法创建对象
ip,子网掩码,网关,IPS与IDS
arguments
【TOOLS】TortoiseSVN如何设置比较工具为Beyond Compare 4
[audio] transplant wm8978 audio codec driver based on STM32 I2S
随机推荐
2022-07-21: given a string STR and a positive number k, you can divide STR into multiple substrings at will, in order to find that in a certain division scheme, there are as many palindrome substrings
Go 并发模式:管道和取消
使用工厂的方法创建对象
ecshop配置微信支付,微信开发者工具微信支付时弹窗提示“未绑定网页开发者”问题
Try kolla-ansible (by quqi99)
[SDIO] sd2.0 protocol analysis summary (I) -- Introduction to SD card basic probability
Internet download manager2022 trial (IDM for short)
OSI模型,TCP/IP模型
TCP与UDP及三次握手,四次挥手
【SDIO】SD2.0协议分析总结(二)-- SD卡识别&数据传输过程
Protocol and port
ECSHOP disable cache and close cache
批量查分爬虫
[SDIO] SDIO, SD card, FatFs file system related article index
07.合成复用原则(Composite/Aggregate Reuse Principle,CARP)
charm zaza functional test (by quqi99)
Codeforces Round #799 (Div. 4)(8/8)
Add the GD Library under centos7.5, and then the MySQL expansion library. There is no problem without the configuration of MySQL expansion. There is no MySQL expansion in phpinfo
centos7.5下添加gd库然后mysql拓展库没了mysql拓展的配置也没问题,phpinfo中就是没有mysql拓展
web新手区