当前位置:网站首页>Leetcode: 185. all employees with the top three highest wages in the Department
Leetcode: 185. all employees with the top three highest wages in the Department
2022-07-22 19:07:00 【A master of East and West】
The original title is :https://leetcode-cn.com/problems/department-top-three-salaries/
Personal solution :
benefit use window mouth Letter Count : Using window functions : benefit use window mouth Letter Count :
# Write your MySQL query statement below
select d.Name as Department, e2.Name as Employee, Salary
from (
select Name, Salary, DepartmentId
from (
select *, dense_rank() over(partition by DepartmentId order by Salary desc) as ranking
from Employee
) as temp
where ranking < 4
) as e2
left join Department d
on e2.DepartmentId = d.Id
where d.Id IS NOT NULL;
Not efficient enough :
Official solution :
SELECT
d.Name AS 'Department', e1.Name AS 'Employee', e1.Salary
FROM
Employee e1
JOIN
Department d ON e1.DepartmentId = d.Id
WHERE
3 > (SELECT
COUNT(DISTINCT e2.Salary)
FROM
Employee e2
WHERE
e2.Salary > e1.Salary
AND e1.DepartmentId = e2.DepartmentId
)
;
The official solution is ingenious where The logic in the clause , use e1 Of Salary Do external circulation ,e2 Of Salary Do internal circulation , So as to determine the qualified e1.Salary, Then the qualified employees are determined .
however , Whoa !, I didn't expect the official efficiency to be worse than my own … Only 12.36%
follow-up :
I went back and ran my code again ( Code of personal solution ), Found defeated 99.52% Users of , What about this ? The sky is confused and the earth is confused , You are ignorant and I am ignorant , Is really ignorant !
边栏推荐
- [sliding window technique] 76. Minimum covering substring
- Leetcode 116. fill in the next right node pointer of each node
- 1. Closeable of qtablewidget, 2.pro/build_ pass、member,3.QString&&
- 二、IDEA搭建JFinal项目+代码自动生成+数据库操作测试(三种方式)
- Sorting of in-depth learning materials
- JVM调优实战-从零开始 | 项目有关JVM调优总结
- leetCode笔记
- Transformer再下一城!low-level多个任务榜首被占领,北大华为等联合提出预训练模型IPT
- PTA exercise 8-8 judging palindrome string
- 二、IDEA搭建JFinal項目+代碼自動生成+數據庫操作測試(三種方式)
猜你喜欢
Flink学习笔记(六)Flink的时间和窗口
Flink学习笔记(五)DataStream API
How to resolve errors in executing the yum makecache command
numpy.reshape完成图像切割
Wechat scans the QR code of the website, but only displays the link address, and cannot jump to the web page
paper - A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
二、IDEA搭建JFinal项目+代码自动生成+数据库操作测试(三种方式)
Strncpy() copy string (limited by length)
JVM tuning practice - start from scratch | summary of JVM tuning related to the project
paper - A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
随机推荐
1.qt view source code
JVM tuning practice - start from scratch | summary of JVM tuning related to the project
Programmer interview golden code interview question 01.02. determine whether it is character rearrangement
1. Create a dynamic library of functions, 2. Howto create and deploy a sample DLL using MinGW
Writing word accumulation
Leetcode: 184. the highest paid employee in the Department
用LaTeX写论文时如何加资助信息
Flink学习笔记(三)Flink安装部署
[summary of linked list skills] 876. Intermediate node of linked list
BigDecimal中除法divide()方法的详细解析,带你走进源码的world
音频 3A 处理实践,让你的应用更「动听」
Leetcode 720. the longest word in the dictionary
服务器磁盘IO性能调优
[yolov5 practice 4] traffic sign recognition system based on yolov5 - model test and evaluation
mysql执行过程以及顺序
mysql主从复制
Stm32+esp8266+mqtt protocol connects onenet IOT platform
数据优化的方式
PTA exercises 8-6 delete characters
Go language learning: go language journey - exercise questions and reference answers