What is the SQL for 'next' and 'previous' in a table?

后端 未结 7 861
抹茶落季
抹茶落季 2020-12-05 12:21

I have a table of items, each of which has a date associated with it. If I have the date associated with one item, how do I query the database with SQL to get the \'previous

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 12:46

    If your RDBMS supports LAG and LEAD, this is straightforward (Oracle, PostgreSQL, SQL Server 2012)

    These allow to choose the row either side of any given row in a single query

提交回复
热议问题