看你按什么排序了,假设你是按id排序,你可以这样
select top 11 * 
from (
select top 20 * 
from yourtable
where id=a.id 
order by id desc
)
order by id

解决方案 »

  1.   

    select top 10 * 
    from (
    select top 20 * 
    from tablenameorder by id asc
    )a
    order by id desc
      

  2.   


    select top 11 * from
    (
    select top 20 * 
    from tb
    order by [id] 
    )a
    order by [id] desc
      

  3.   

    或者你可以按分页走,这样
    declare @x int
    declare @y int
    set @x=1
    set @y=10
    select * from tb
    where [id] between (@x-1)*@y and @x*@y
      

  4.   

    错了上面是前10条记录
    declare @x int
    declare @y int
    set @x=2
    set @y=10
    select * from tb
    where [id] between (@x-1)*@y and @x*@y
      

  5.   

    现在情况如下:我确实想实现分页功能,以id为主键,每页依次显示出倒序的十条数据,
    但我的id是不连续的整数
    如果我要选中按id倒序排第90到100个数据,该如何做?
      

  6.   

    如果这样的话,你用identity(int,1,1)生成中间表如何呢?
    select *
    into #tb
    from yourtable
    declare @x int
    declare @y intset @x=9
    set @y=10
    select * from #tb
    where [id] between (@x-1)*@y and @x*@ydrop table #tb
      

  7.   

    又错了,晕死了
    select id=identity(int,1,1),*
    into #tb
    from yourtable
    declare @x int
    declare @y intset @x=9
    set @y=10
    select * from #tb
    where [id] between (@x-1)*@y and @x*@ydrop table #tb
      

  8.   

    select [id]=identity(int,1,1),a.* into #t from employee a
    select * from #t where [id]<=20 and [id]>=10
      

  9.   

    -- 以id为主键,每页依次显示出倒序的十条数据,但我的id是不连续的整数--示例存储过程
    create proc p_qry
    @page int   --查询第几页
    as
    set nocount on
    if @page=1 --第一页,直接查询即可
    begin
    set rowcount 10
    select * from 表 order by id desc
    end
    else
    begin  
    --屏蔽的记录条数
    set @page=(@page-1)*10
    set rowcount @page
    select id into #t from 表 order by id desc --查询出结果
    set rowcount 10
    select * from 表 a
    where not exists(select 1 from #t where id=a.id)
    order by id desc
    end
    go--调用
    exec p_qry 2
      

  10.   

    方案二:
    alter table tb1 add  [id] decimal(38,0) identity(1,1)
    select * from tb1 where [id]<=20 and [id]>=10
    alter table tb1 drop column [id]
      

  11.   

    select F=identity(1,1),* into #t from table
    select * from #t where F<=20 and F>=10
    drop table #t
      

  12.   

    看来我的SqlServer还差大家一大截
    大家的解答我正在消化理解
      

  13.   

    select top 10 * from 表 where 主键 not in (select top 10 主键 from 表)
      

  14.   

    zhujainf() 我才学呢 呵呵 共同进步哦
      

  15.   

    select top 10 * from 
    (select top 20 * from tb order by col1 desc)
    order by col1 ASC
      

  16.   

    本人有一方法可行,不过有点麻烦,大家不要笑话,本人实属初学者--给你的表增加一列,用identity(1,1),导到一个新临时表中去
    select identity(int,1,1) as id,* into #新表名 from yourtable
    --然后用新列id来标识,就可以看到20到30之间的记录
    select * from #新表名 where bewtten 20 and 30
    --再去掉增加上去的新列名就行了