比如说数据库表A中有一些项,ID为主键且自增1,表中起初有50项且ID为1至50,现在我随机地删除其中不连续的10项,现在表中还有40项,但他们的ID不在是1至50的连续数,我如何得到剩下的40项中的第20至第30项的内容,这个select语句怎么写?select * from A where .........下面怎么写查询条件?   蹲等中,先谢谢了!

解决方案 »

  1.   

    create table test
    (id int identity(1,1),
    sdate datetime,
    edate datetime)insert test(sdate,edate)
    select '2006-7-25','2006-7-26' union all 
    select '2006-7-26','2006-7-26' union all
    select '2006-7-27','2006-7-29' union all
    select '2006-7-27','2006-7-27' union all
    select '2006-7-28','2006-7-30' union all
    select '2006-7-29','2006-7-30'delete from test where id=1 or id=3select top 2 * from (select top 3 * from test order by id desc)a
    order by idselect * from test
      

  2.   

    select top 11 * from A
    where id not in(select top 19 id from A)
      

  3.   

    select top 11 * from A where id not in(select top 19 id from A)
    是这个啦,以前有人问过的。
      

  4.   

    Select Top 10 * 
    From 
    ( Select Top 30 * From tb Order by 1 Desc) A
      

  5.   

    select top 20 * 
    from   (
           select top 30 * 
           from   a
           order  by id desc
           )
    order  by id
      

  6.   

    select top 20 * 
    from   (
           select top 30 * 
           from   a
           order  by id desc
           ) a  -- 打掉个字哈。
    order  by id
      

  7.   

    select top 11 * from tablename where id not in (select top 19 id from tablename order by id desc) order by id