sql pulling a row for next or previous row of a current row

后端 未结 6 1568
抹茶落季
抹茶落季 2020-12-03 05:51
id    |  photo title     |  created_date

XEi43 |  my family       |  2009 08 04
dDls  |  friends group   |  2009 08 05
32kJ  |  beautiful place |  2009 08 06
EOIk  |  wo         


        
6条回答
  •  暖寄归人
    2020-12-03 06:21

    Horrible hack - I don't like this but might work..

    with yourresult as
    (
    select id, photo_title, created_date, ROW_NUMBER() over(order by created_date) as 'RowNum' from your_table
    )
    -- Previous
    select * from yourresult where RowNum = ((select RowNum from yourresult where id = '32kJ') -1)
    -- Next
    select * from yourresult where RowNum = ((select RowNum from yourresult where id = '32kJ') +1)
    

    That of any use?

提交回复
热议问题