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

后端 未结 7 883
抹茶落季
抹茶落季 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条回答
  •  猫巷女王i
    2020-12-05 12:42

    Try this...

    SELECT TOP 3 * FROM YourTable
    WHERE Col >= (SELECT MAX(Col) FROM YourTable b WHERE Col < @Parameter)
    ORDER BY Col
    

提交回复
热议问题