① select * from table limit 2,1;
//含义是跳过2条取出1条数据,limit后面是从第2条开始读,读取1条信息,即读取第3条数据
② select * from table limit 2 offset 1;
//含义是从第1条(不包括)数据开始取出2条数据,limit后面跟的是2条数据,offset后面是从第1条开始读取,即读取第2,3条
select
IFNULL
(
(select distinct salary
from Employee
order by salary Desc
limit 1 ,1),
null
)as SecondHighestSalary
例
select distinct 成绩
from 成绩表
where 课程=‘语文’
order by 课程,成绩 desc
limit 1,1;
```bash
在这里插入代码片
高级版 得到第N高的salary
CREATE FUNCTION getNthHighestSalary(N INT)
RETURNS INT
BEGIN
set N=N-1;
if N<0 then
RETURN null;
else
return
( # Write your MySQL query statement below.
select ifnull
(
(select distinct Salary
from Employee
order by Salary desc
limit N, 1),null)
as getNthHighestSalary
);
END if;
End