mysql中,编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。

标题:mysql中,编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。

一、题目

mysql中,编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。_第1张图片二、解题

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  declare result int;
  set result=N-1;
  RETURN (
      # Write your MySQL query statement below.
      select ifnull(
                    (
                    select distinct salary
                    from employee
                    order by salary desc
                    limit result,1     
                    )
          ,null) 
  );
END

你可能感兴趣的:(#mysql数据结构lc)