1. 遇到的问题
已知一个题库,希望实现当前页切换上一题,下一题的需求。
查看得知,数据库中用于查询的字段(主键)是不连续的。如上图所示:stxh为主键number类型。
2. 实现方式lead over
2.1 实现代码
下一条
select nowId, afterId from(
SELECT stxh nowId, lead(stxh,1) over (order by stxh) as afterId from EXM_KSTK)
where afterId-nowId>0 and nowId = 54;
上一条
select beforeId, nowId from(
SELECT stxh beforeId, lead(stxh,1) over (order by stxh) a