CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
WITH P AS (SELECT *, DENSE_RANK() OVER(ORDER BY Salary DESC) AS salary_rank
FROM Employee)
SELECT DISTINCT P.Salary
FROM P
WHERE P.salary_rank = N
);
END
select Department,Employee,Salary from
(
select e.Name as Employee, e.Salary,d.Name as Department,DENSE_RANK() over(partition by DepartmentId order by Salary desc) as seq from Employee as e join
Department as d on e.DepartmentId = d.Id
)T where T.seq <= 3
网友评论