MSSQL 2008 R2 选择特定范围内的行 - 分页 - 最好的方法是什么
目前这个sql查询能够在我确定的行之间进行选择。但有没有更好的方法呢?
select * from (select *, ROW_NUMBER() over (order by Id desc) as RowId
from tblUsersMessages ) dt
where RowId between 10 and 25
Currently this sql query is able to select between the rows i have determined. But are there any better approach for this ?
select * from (select *, ROW_NUMBER() over (order by Id desc) as RowId
from tblUsersMessages ) dt
where RowId between 10 and 25
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于你的索引。
这可能会更好
有时,如果存在可用于快速查找范围内的
Id
值的较窄索引, 。 查看我的请在此处回答以获取演示可能出现的问题类型的示例。您需要针对您的具体情况检查
SET STATISTICS IO ON
的执行计划和输出。Depends on your indexes.
Sometimes this can be better
If a narrower index exists that can be used to quickly find the
Id
values within the range. See my answer here for an example that demonstrates the type of issue that can arise.You need to check the execution plans and output of
SET STATISTICS IO ON
for your specific case.