码迷,mamicode.com
首页 > 数据库 > 详细

T-SQL备忘(4):分页

时间:2015-04-21 00:18:23      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

set statistics io on 
set statistics time on 
--SQL Server 2012分页方式 
select * from Production.Product 
order by ProductID offset 20 row fetch next 10 rows only  
--SQL Server 05/08分页方式 
go 
with cte as  
( 
 select row_number() over(order by productid) as rowNum,* from production.product 
) 
select * from cte where rowNum>20 and rowNum<=30 
--or  
select * from (select row_number() over(order by productid) as rowNum,* from production.product) cte 
where rowNum>20 and rowNum<=30

--通用方式 
select top 10 * from Production.Product where ProductID not in 
( 
   select top 20 ProductID from Production.Product order by ProductID 
) order by ProductID 

select top 10 * from Production.Product where ProductID> 
( 
 select max(ProductID) from (select top 20 ProductID from Production.Product order by ProductID) as temp 
) order by ProductID 

  

T-SQL备忘(4):分页

标签:

原文地址:http://www.cnblogs.com/fengchengjushi/p/4442904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!