语句是这样的
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
为啥会出现这种情况呢
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
为啥会出现这种情况呢
解决方案 »
- 用SQL Server Management Studio Express 在sql2005里如何建立一个整形自增的主键啊?
- 关于编码的问题
- 表锁定的问题
- 哈,跳到sqlserver来给分?如何使用存储过程在作业中调用本地数据远程传到远程服务器上。
- SQL SERVER2000的DATA目录下的文件问题
- 关于表结构设计
- 触发器中的奇怪问题
- 一个比较棘手的问题!请大家帮忙!谢谢
- 请问:建表时的“PRIMARY KEY”约束和“UNIQUE”约束有哪些不同啊?
- 被引用表"bumen"中不存在与外键"FK_sit_488396b9e5f75e739434"中的引用列表匹配的主键或候选键。
- sql2005不同版本的数据迁移问题
- sql语句出错了,菜鸟求救
这是为啥啊
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)
确实是这样的啊^_^ 但是为什么前面的可以啊
所用的索引? 可以解释一下吗 发个网址也行啊 不胜感激啊 还有啊
还有 这个语句
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
- 查sqlserver的帮助看看什么是索引,和执行计划,辅助于google - 没有名字的话怎么被引用呢……