找出51筆到75筆的資料
通常用在分頁
要加ORDER BY
use Northwind
GO
SELECT * FROM Orders
ORDER BY OrderID
OFFSET 50 ROWS FETCH NEXT 25 ROWS ONLY
分頁效果(每頁25筆,顯示第2頁的資料)
DECLARE @pagesize AS BIGINT = 25, @pagenum AS BIGINT = 2;
SELECT *
FROM Orders
ORDER BY OrderID DESC
OFFSET (@pagenum - 1) * @pagesize ROWS FETCH NEXT @pagesize ROWS ONLY;
沒有留言:
張貼留言