문제 URL : 185. Department Top Three Salaries
Department Top Three Salaries - LeetCode
Can you solve this real interview question? Department Top Three Salaries - Table: Employee +--------------+---------+ | Column Name | Type | +--------------+---------+ | id | int | | name | varchar | | salary | int | | departmentId | int | +--------------
leetcode.com
푸는방법은 다양합니다.
with 를이용하여 dense rank over partition으로 분리해서 랭크를 주니 훨씬 쉽더군요
소스코드 :
# Write your MySQL query statement below
with temp as(
select name,salary,dense_rank() over(partition by departmentid order by salary desc) grade, departmentid from employee)
select d.name Department,t.name Employee, t.salary Salary
from temp t
inner join department d on d.id = t.departmentid
where grade<=3
sql 은 시간줄이는 방법을 잘 모르겠더군요 똑같은 답을 내도 시간이 더 짧게 나올때도있고 느리게나올때도있고
제각각.. ㅋㅋㅋ
궁금한점은 언제든 댓글 주시길 바랍니다.
'LeetCode' 카테고리의 다른 글
[LeetCode] 76. Minimum Window Substring (0) | 2023.09.12 |
---|---|
[LeetCode] 34. Find First and Last Position of Element in Sorted Array (0) | 2023.09.12 |
[LeetCode] 239. Sliding Window Maximum (0) | 2023.09.06 |
[LeetCode] 240. Search a 2D Matrix II (0) | 2023.09.06 |
[LeetCode] 223. Rectangle Area (2) | 2023.09.06 |