zoukankan      html  css  js  c++  java
  • Select top number * from table 实现分页

    (select top 5000 id from table)(注明:table是表名,id是表的索引列) 
      
    解决了select top 速度慢的问题,实现高效分页查询! 
    当用select top 10 * from table where id not in(select top 5000 id from table)这个语句时,单是查询5000行后的10行,速度慢的惊人,要是数字更大的话,可能会卡死,下面这个终于解决了这个烦人的问题,如下: 
    select * from (SELECT top 10 * FROM (select top 5000 * from t_people )order by id desc ) order by id ; 
    思路是:先select top 5000 ,,即是先拿出1~ 5000行,然后从这5000中倒序之后拿出10行,再之后倒序。。 
    测试:查询第九万行的后十行,不用一秒时间。 
    原因:导致分页查询速度慢的原因,应该是not in 这个嵌套语句的问题 
     
    对于这个,**提出下面的sql语句: 
    select top 10 * from people where id>(select max(id) from(select top 5000id from people order by id)) 
    对于这条语句,经过测试,感觉上比上一个方法慢了一点点,,我感觉应该是查询了两次people表的原因 
     
  • 相关阅读:
    手机市场价格尚待规范
    Hotmail的2G邮箱被收回,只剩250M了
    网格50题(zz)
    Wallop介绍
    Hotmail邮箱居然还有2G
    IE 7.0抛弃Win2000用户?(zz)
    祝各位Blogger新春快乐!
    Gmail Invitation
    A CS Research Topic Generator(zz)
    今天"做大岁"
  • 原文地址:https://www.cnblogs.com/qanholas/p/2040551.html
Copyright © 2011-2022 走看看