假如一个A表有40条记录我怎么得到23到33之间的记录,没有编号

解决方案 »

  1.   

    select top(33)from table where not in (select top(23))
      

  2.   

    select top(33)from table where not in (select top(23))
      

  3.   

    楼上两位真的快...
    select   identity(int,1,1)   as   序号,usid,usname   into   #1   from   表   
    select   *   from   #1  where 序号 BETWEEN 22 and 33
      

  4.   

    DECLARE @BeginIndex INT,@EndIndex INT SET @BeginIndex = 23
    SET @EndIndex = 33 BEGIN WITH TempTable AS(
    SELECT *, Row_Number() OVER(ORDER BY 主键 DESC) AS RowNumber
    FROM YourTable)
    SELECT TempTable.*
    FROM TempTable 
    WHERE TempTable.RowNumber BETWEEN @BeginIndex AND @EndIndex
    END看看别人分页的存储过程
      

  5.   

    楼上两位真的快...
    select   identity(int,1,1)   as   序号,usid,usname   into   #1   from   表   
    select   *   from   #1  where 序号 BETWEEN 22 and 33
    -----------
    这位老兄直接都给你添加编号了
    想查多少都行
      

  6.   

    showrock(玉蝴蝶) 正解
    use pubs
    select identity(int,1,1) as 序号,fname into #1 from employee
    select * from #1 where 序号 BETWEEN 22 and 33
      

  7.   

    玉蝴蝶是先给你的表添加序列号,但是如果表的数据如果太大,就会造成一点点运行速度的问题。稍微修改一下:因为你只要选最多33条,这样可以满足条件。select TOP 33  identity(int,1,1)   as   序号,usid,usname   into   #1   from   表   
    select   *   from   #1  where 序号 BETWEEN 22 and 33用一条select也可以解决
    select top 12 from (select top 33 from 表)
    这里的12其实就是33-22+1=12(22到33一共12条纪录)
      

  8.   

    有点问题,修改如下
    select top 12 * from (select top 33 * from 表) 临时表
      

  9.   

    select top 10 * from (select top 33 * from tab ) as a order by id desc
      

  10.   

    showrock(玉蝴蝶)  正解
    select   identity(int,1,1)   as   序号,* into   #t   from  table   
    select   *   from   #t  where 序号 BETWEEN 22 and 33学习了.
    先为其无序号表添加一个替代自动生成列并把他写入临时表T中
    再从临时表T中去读取相应范围的记录,问题解决
    LZ注意,两条SQL语要一起运行哈~
      

  11.   

    select TOP 33  identity(int,1,1) as  序号,usid,usname into #1 from  A   
    select   *   from   #1  where 序号 BETWEEN 22 and 33 或select top 12 * from (select top 33 * from 表) 临时表   
    正解!
      

  12.   

    select   identity(int,1,1)   as   序号,* into   #t   from  table   
    select   *   from   #t  where 序号 BETWEEN 22 and 33
    最好的方法。