语句是这样的
 select top * from person.contact where contactid not in(select top 10 contactid form person.contact)
  能返回 contactid 为11~20的记录集合
 select top * from person.contact where contactid not in(select top 20 contactid form person.contact)
  能返回 contactid 为21~30的记录集合。。直到
select top * from person.contact where contactid not in(select top 90 contactid form person.contact)却返回了 11~20行的数据测试用的数据库 是微软的示例数据库 Adventureworks
为啥会出现这种情况呢  
 

解决方案 »

  1.   

    改成 select top * from person.contact where contactid not in(select top 90 contactid form person.contact order by contactid asc) 就没问题了
    这是为啥啊 
      

  2.   

    是不是person.contact 这个表只有90行
      

  3.   

    top 没参数不能运行啊..怎么可能能运行呢?
      

  4.   

    没什么怪异
    select top 10 * from person.contact where contactid not in(select top 10 contactid from person.contact)
    select top 10 * from person.contact where contactid not in(select top 90 contactid from person.contact) 
    这两个语句的执行计划用的索引是不一样的,在没有order by的情况下用的索引的顺序决定了top出来的结果是什么,你看下select top 90 contactid from person.contact的结果是什么就知道了解决的方法就是加上order by
    select top 10 * from person.contact where contactid not in(select top 90 contactid from person.contact order by contactid)
      

  5.   

    “这两个语句的执行计划用的索引是不一样的,在没有order by的情况下用的索引的顺序决定了top出来的结果是什么,你看下select top 90 contactid from person.contact的结果是什么就知道了”
    确实是这样的啊^_^ 但是为什么前面的可以啊
    所用的索引? 可以解释一下吗 发个网址也行啊 不胜感激啊 还有啊
    还有 这个语句
    select * from(select ROW_NUMBER()over(order by ContactID asc) as rowid,* from Person.Contact)as t where rowid > 90 and rowid<100
    把其中表别名去掉 就报错 为啥啊 即如下下便报错
    select * from(select ROW_NUMBER()over(order by ContactID asc) as rowid,* from Person.Contact)  where rowid > 90 and rowid<100
      

  6.   

    select top m * from tablename where id not in (select top n id from tablename) 这种写法是取第n条记录后的m条记录
      

  7.   


     - 查sqlserver的帮助看看什么是索引,和执行计划,辅助于google - 没有名字的话怎么被引用呢……