您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍了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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。