SQL Server无主键分页

2017-09-07 10:31:46来源:oschina作者:别俊人点击

分享
declare @start int,@end int;
select convert(varchar,StartTime,120) as StartTime,SessionId,UserId from(
select * from (
select ROW_NUMBER() over (order by StartTime desc) as sno,* from(
select distinct a.SessionId,b.StartTime,b.UserId from Verification.VerificationResult as a
left join Task.Session as b on a.SessionId = b.SessionId
) as C
) as D
where sno between @start and @end
) as Q

其中还需要再结果集中LEFT JOIN 另一个表,测试查询10条数据,需要5秒,比使用临时表略快0.1,总体性能还有待更好的办法解决。Sql Server没有MySQL的limit真是不方便。

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台