Find the n-th high

First, find the n-th high salary
Here Insert Picture Description

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  set N=N-1;
  RETURN (
      select distinct(salary) from employee order by salary desc limit N,1
      
  );
END

Because the page limit from 0 to take the first one is 0 (this is still do not understand)

limit offset:\

* from limit Table 2 SELECT 1 offset;
// the article 1 (not including) the start of data extracted two data, with the latter two is to limit the data is read from the offset back to article 1, i.e., read the first 2,3 bar

Second, look for the second-highest salary

Here Insert Picture Description

select max(Salary) as SecondHighestSalary
from employee
where
salary<(select max(salary) from employee)
Released four original articles · won praise 0 · Views 33

Guess you like

Origin blog.csdn.net/meira_go/article/details/104924806