在SQL Server中,有幾種不同的方法可以進行分頁操作:
SELECT *
FROM table
ORDER BY column
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY column) AS RowNum
FROM table
) AS SubQuery
WHERE RowNum BETWEEN 11 AND 20;
WITH CTE AS (
SELECT *,
ROW_NUMBER() OVER (ORDER BY column) AS RowNum
FROM table
)
SELECT *
FROM CTE
WHERE RowNum BETWEEN 11 AND 20;
這些是在SQL Server中進行分頁操作的幾種常見方法。具體選擇哪種方法取決于你的需求和查詢的復雜性。