网站直播用php怎么做的,二维码制作,群晖 卸载wordpress,盐城做网站企业1. 遇到的问题 已知一个题库#xff0c;希望实现当前页切换上一题#xff0c;下一题的需求。 查看得知#xff0c;数据库中用于查询的字段(主键)是不连续的。如上图所示#xff1a;stxh为主键number类型。 2. 实现方式lead over 2.1 实现代码 下一条
select nowId, afte… 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-nowId0 and nowId 54;上一条
select beforeId, nowId from(
SELECT stxh beforeId, lead(stxh,1) over (order by stxh) as nowId from EXM_KSTK)
where nowId-beforeId0 and nowId 54; 2.2 lead方法说明 lead(value_expr [,offset][,default]) over([query_partition_clause] order by Order_by_clause) value_expr值表达式通常是字段也可是是表达式。 offset偏移如果0 表示与当前行相比向前的行数。默认值为1 default默认值偏移结果不存在时默认的返回值。 2.3 分析实现代码 以上一条为例吧主要分析lead over 部分 SELECT 字段名 beforeId, lead(在字段名,偏移量) over (order by 字段名) as nowId from 表名) 整条的使用就是需要传入当前的nowId值 3. 结合需求完善sql 3.1 上一条(主键stxh) 首先需要通过当前id获取上一条记录id值 select beforeId from(SELECT stxh beforeId, lead(stxh,1) over (order by stxh) as nowId from EXM_KSTK)
where nowId-beforeId0 and nowId 54; 通过这条sql就拿到上一条的id值了然后再select查询即可。 SELECT * FROM EXM_KSTK stxh
(select beforeId from(SELECT stxh beforeId, lead(stxh,1) over (order by stxh) as nowId from EXM_KSTK) where nowId-beforeId0 and nowId 54
) 3.2 下一条(主键stxh) 直接贴代码吧。 SELECT * FROM EXM_KSTK stxh
(select afterId from( SELECT stxh nowId, lead(stxh,1) over (order by stxh) as afterId from EXM_KSTK) where afterId-nowId0 and nowId 54
) 3.3 补充说明 EXM_KSTK表名 stxh我的表主键 54上文所用到的54就是你需要去传入的当前已知的id值 博客地址https://www.cnblogs.com/niceyoo