1. 程式人生 > >oracle 查詢當前記錄的上一條記錄或下一條記錄

oracle 查詢當前記錄的上一條記錄或下一條記錄

上一條

select *

  from cms_article a
 where id = (select c.p
               from (select t.id, lag(t.id, 1, 0) over(order by t.sort) as p
                       from cms_article t) c
              where c.id = '8a3e56b6396630260139663fa32d01e1');

下一條


select a.id,a.title
  from cms_article a
 where id = (select c.p

               from (select t.id, lead(t.id, 1, 0) over(order by t.sort,t.eidt_date) as p
                       from cms_article t ) c
              where c.id = '8a3e56b6396630260139663fa32d01e1');