从某个表里面读取第十行到第十五行数据的最快方法是哪一种?

解决方案 »

  1.   

    select top 5 * 
    from (select top 15 * from 表 order by 主键列 asc)a 
    order by order by 主键列 desc
      

  2.   

    select top 6 a.*
    from 表 a
    left join
    (select top 9 主键 from 表) b
    where b.主键 is null
      

  3.   

    /*取N到M条记录公式并按ID升序排列*/
    Select 
          *
    From (
          Select 
                Top M-N+1 * 
          From (
                Select Top M * From 表 
                ) T 
          Order By ID Desc
          ) TT
    Order By ID/*取N到M条记录公式并按ID降序排列*/
    Select 
          Top M-N+1 * 
    From (
          Select Top M * From 表 
          ) T 
    Order By ID Desc
      

  4.   

    ----如果没有主键就用临时表select id=identity(int,1,1),* into # from 表 select * from # where id between 10 and 15
      

  5.   

    从某个表里面读取第十行到第十五行数据的最快方法是哪一种?
    select top 6 * from tablea where ID not in (select top 9 ID tablea)
    --选择n到m条数据
    select top  m-n+1 *  from tablea where ID not in (select top n-1 ID from tablea)
    如果是10-15条的话not in 就可以了,只是个例子的话“学习”中~~~
      

  6.   

    ---测试
    Select Top 100 ID=Identity(int,1,1) Into # From sysColumns A,sysColumns B---取第10到15条数据按ID升序排
    Select 
          *
    From (
          Select 
                Top 6 *   /*15-10+1=6*/
          From (
                Select Top 15 * From # 
                ) T 
          Order By ID Desc
          ) TT
    Order By ID