我想从表中取出第7条到第16条之间的记录,怎么写呀。

解决方案 »

  1.   

    select top 10 from tablename a where not exists (select top 7 from tablename where a.col1=col1 and a.col2=col2…………)
      

  2.   

    select top 10 * from 
    (select top 16 * from tablename)t1
    order by id descselect top 16 * from tablename 
    where id not in
    (select top 6 id from tablename)
      

  3.   

    Select TOP 10 *From TableName Where ID Not In(Select TOP 6 ID From TableName Order By ID) Order By ID
      

  4.   

    select [id]=identity(int,1,1),* into # from 表
    select * from # between 7 and 16drop table #
      

  5.   

    select [id]=identity(int,1,1),* into # from 表
    select * from # where id between 7 and 16drop table #
      

  6.   

    --以下示例取得第4到第6條紀錄Create Table TEST(ID Int,Name Varchar(10))
    Insert TEST Select 1,'aa'
    Union All Select 2,'bb'
    Union All Select 3,'cc'
    Union All Select 5,'dd'
    Union All Select 7,'ee'
    Union All Select 8,'ff'
    Union All Select 9,'gg'
    GO
    Select TOP 3 * From TEST Where Id Not In ( select top 3 ID from TEST order by id) Order By ID
    GO
    Drop table TEST
    --Result
    /*
    ID Name
    5 dd
    7 ee
    8 ff
    */