您好,登錄后才能下訂單哦!
這篇文章主要介紹了SQL Server分頁的方法有哪些的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇SQL Server分頁的方法有哪些文章都會有所收獲,下面我們一起來看看吧。
SELECT TOP 3 [SalesOrderID], [RevisionNumber], [OrderDate] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] WHERE [SalesOrderID] NOT IN ( SELECT TOP 15 [SalesOrderID] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ORDER BY [SalesOrderID] ) ORDER BY SalesOrderID;
備注: 注意前后的order by 一致
SELECT [SalesOrderID], [RevisionNumber], [OrderDate] FROM ( SELECT [SalesOrderID], [RevisionNumber], [OrderDate] , ROW_NUMBER() OVER ( ORDER BY SalesOrderID ) AS rowid FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ) cte WHERE rowid BETWEEN 16 AND 18;
SELECT [SalesOrderID], [RevisionNumber], [OrderDate] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ORDER BY SalesOrderID OFFSET 15 ROW FETCH NEXT 3 ROWS ONLY;
DECLARE @page INT, @size INT, @Total INT; SELECT @page = 3, @size = 10; --當前頁面為3,頁面大小為10 -------方法一 SELECT TOP ( @size ) [SalesOrderID], [RevisionNumber], [OrderDate] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] WHERE [SalesOrderID] NOT IN ( SELECT TOP (( @page - 1 ) * @size ) [SalesOrderID] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ORDER BY [SalesOrderID] ) ORDER BY SalesOrderID; -------方法二 SELECT [SalesOrderID], [RevisionNumber], [OrderDate] FROM ( SELECT [SalesOrderID], [RevisionNumber], [OrderDate] , ROW_NUMBER() OVER ( ORDER BY SalesOrderID ) AS rowid FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ) cte WHERE rowid BETWEEN ( @page - 1 ) * @size + 1 AND @page * @size; -------方法三 SELECT [SalesOrderID], [RevisionNumber], [OrderDate] FROM [AdventureWorks2012].[Sales].[SalesOrderHeader] ORDER BY SalesOrderID OFFSET ( @page - 1 ) * @size ROWS FETCH NEXT @size ROWS ONLY; ---offset的當前頁面是從零開
關于“SQL Server分頁的方法有哪些”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“SQL Server分頁的方法有哪些”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。