在一个数据库中,有三十条记录,其中id是主键,其它条件不知,怎么样找到中间十条的记录??在线等。谢谢

解决方案 »

  1.   

    select top 10 * from 
    (select top 20 * from tablename)t
    order by id descselect top 10 * from tablename 
    where id not in (select top 10 id from tablename)
    order by id
      

  2.   

    declare @ta table (id int identity(1,1),name varchar(10))insert into @ta select 'a1' union all select 'a2' union all select 'a3' union all select 'a4'
    union all select 'a5' union all select 'a6' union all select 'a7' union all select 'a8' union all select 'a9' union all select 'a10'
    union all select 'a11' union all select 'a12' union all select 'a13' union all select 'a14'
    union all select 'a15' union all select 'a16' union all select 'a17' union all select 'a18' union all select 'a19' union all select 'a20'
    union all select 'a21' union all select 'a22' union all select 'a23' union all select 'a24' union all select 'a25' 
    union all select 'a26' union all select 'a27' union all select 'a28' union all select 'a29' union all select 'a30'  union all select 'a31'
    --如果要取出从第15到第24条(中间10条),那么就是select top 10 * from @ta 
    where id not in(select top 14 id from @ta)
      

  3.   


    select IDENTITY(INT, 1, 1) as id,tabname.*  into ##tab from tabname 
    select * from ##tab where id between ... and ...