sql 177. Nth Highest Salary(1st).sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 177. Nth Highest Salary(1st).sql相关的知识,希望对你有一定的参考价值。

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  DECLARE Nth INT;
  SET Nth = N;
  RETURN (
      # Write your MySQL query statement below.
      SELECT DISTINCT A.Salary //Subquery may more than one row
      FROM Employee AS A
      WHERE (SELECT COUNT(DISTINCT(B.Salary)) FROM Employee AS B WHERE B.Salary >= A.Salary) = Nth
  );
END
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M = N-1;
  RETURN (
      # Write your MySQL query statement below.
      SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M,1
  );
END

以上是关于sql 177. Nth Highest Salary(1st).sql的主要内容,如果未能解决你的问题,请参考以下文章

sql 177. Nth Highest Salary(1st).sql

sql 177. Nth Highest Salary(1st).sql

sql 177. Nth Highest Salary(1st).sql

sql 177. Nth Highest Salary(1st).sql

177. Nth Highest Salary (Medium)

177. Nth Highest Salary