美文网首页
window function - leetcode

window function - leetcode

作者: PistachioITer | 来源:发表于2020-06-25 12:54 被阅读0次

    1、第n高的薪水

    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
    

    2、185-部门前三高薪水的员工

    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
    

    相关文章

      网友评论

          本文标题:window function - leetcode

          本文链接:https://www.haomeiwen.com/subject/fidsfktx.html