partition by2 [LeetCode] Department Top Three Salaries (partition by, rank, sub query) select b.Name as Department , a.Name as Employee, a.Salary from (select *, dense_rank() over (partition by DepartmentId order by salary desc) as sal_rank from Employee ) a join Department b on a.DepartmentId = b.Id where a.sal_rank 2021. 4. 10. [LeetCode] Department Highest Salary ( sub query, partition by) # Write your MySQL query statement below select a.Department, a.Employee, a.Salary from (select D.Name as Department, E.Name as Employee, E.Salary, rank() over (partition by D.Name order by Salary desc) as 'rank' from Employee E join Department D on E.DepartmentId = D.Id) as a where a.rank = 1; 서브쿼리부터 보자, from employee 에서 join 으로 employee and deparment을 수행 select 수행 select에서 rank를 사용하는데 여기서 part.. 2021. 4. 10. 이전 1 다음