选择表中5条记录后的记录

时间:2013-10-25 13:06:46

标签: sql sql-server records

我想在表格中的前5条记录之后选择记录。该表正在使用新记录进行更新。我已经显示了5条新记录select top 5 * from table order by ID DESC

现在我想在页面的其他地方显示另外5条记录,对此的查询是什么?

2 个答案:

答案 0 :(得分:0)

WITH tmp AS  
(SELECT ROW_NUMBER() OVER (ORDER BY a.id) AS 'rn', a.* FROM table a)
SELECT * FROM tmp WHERE rn BETWEEN 5 AND 10

答案 1 :(得分:0)

SELECT  *
FROM  [dbo].[4]   
ORDER BY [id] ASC 
OFFSET  5 ROWS 
FETCH NEXT 10 ROWS ONLY