日期:2014-05-20 浏览次数:20774 次
select * from Student where Age>18 order by Age
select * from ( select row_number()over(order by __tc__)__rn__,* from (select top 开始位置+10 0 __tc__,* from Student where Age>18 order by Age)t )tt where __rn__>开始位置
select * from (select top 开始位置+10 row_number()over(order by Id)__rn__, * from Student)t where __rn__>=开始的位置
select * from ( select row_number()over(order by TempColmun) * from ( select top 开始的位置 0 as TempColmun,* from Student order by Id )tt)t where rowNumber >=开始的位置
--插入测试数据200w条,可能会很久 create table Student( Id int PRIMARY KEY identity(1,1), Name nvarchar(50), Age int ) insert Student(Name,Age)values('Name',18) while (select count(*) from Student)<2000000 insert Student select Name,Age from Student
--开始测试查询 declare @now datetime --max方案 select 'max'方案 select @now=getdate() --begin select top 10 * from Student where Id>( select max(Id) from ( select top 1999990 Id from Student order by Id)tt) --end declare @maxDiff int select @maxDiff=datediff(ms,@now,getdate()) --top方案 select 'top'方案 select @now=getdate() --begin select top 10 * from Student where Id not in(select top 1999990 Id from Student) --end declare @topDiff int select @topDiff=datediff(ms,@now,getdate()) --row方案 select 'row'方案 select @now=getdate() --begin select * from ( select row_number()over(order by tc)rn,* from (select top 2000000 0 tc,* from Student)t )tt where rn>1999990 --end declare @rowDiff int select @rowDiff=datediff(ms,@now,getdate()) --row_number方案 select 'row_number'方案 select @now=getdate() --begin select * from( select top 2000000 row_number()over(order by Id)rn,* from Student )t where rn>1999990 --end declare @row_numberDiff int select @row_numberDiff=datediff(ms,@now,getdate()) --记录结果 select '第20万页'页码,@maxDiff max方案,@topDiff top方案,@rowDiff row方案,@row_numberDiff row_number方案