select top 3 Code,Name,Age,Sex from B T1 where Code not EXISTS(SELECT * FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE)
比 not in 复杂啊
select top 3 Code,Name,Age,Sex from B as BB where not exists (select * from B where code <> BB.code)
关键字 'EXISTS' 附近有语法错误。
select top 3 Code,Name,Age,Sex from B T1 where Code not EXISTS(SELECT * FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE) 多了个
select top 3 Code,Name,Age,Sex from B T1 where not EXISTS(SELECT * FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE)
select top 3 Code,Name,Age,Sex from B where Code not in(select top 3 Code from B AND CODE IS NOT NULL)
恩但是 not in 复杂
select top 3 Code,Name,Age,Sex from B b where not exists(select 1 from (select top 3 Code from B) a WHERE a.code=b.code)
加了个IS NOT NULL,可以查出数据,看你的原因
我用 not exists 和 not in 进行 分100w条数据,速度上没多大区别啊,几乎一样。他们说 not in 会使索引无效!
执行时间: 用 not in 是 288 毫秒 用 not exists 是 283 毫秒
not in 可以用到索引吧
NOT IN不能用到索引哦,晕
我查 90w 条以后的数据 依然很快啊那用 not exists 就能用到索引?
[标准SQl Code] select top 3 Code,Name,Age,Sex from B T1 where Code not EXISTS(SELECT Code,Name,Age,Sex FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE)
where Code not EXISTS(SELECT * FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE)
比 not in 复杂啊
where not exists
(select * from B where code <> BB.code)
关键字 'EXISTS' 附近有语法错误。
where Code not EXISTS(SELECT * FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE) 多了个
恩但是 not in 复杂
top 3 Code,Name,Age,Sex
from
B b
where
not exists(select 1 from (select top 3 Code from B) a WHERE a.code=b.code)
用 not in 是 288 毫秒
用 not exists 是 283 毫秒
可以用到索引吧
NOT IN不能用到索引哦,晕
where Code not EXISTS(SELECT Code,Name,Age,Sex FROM (select top 3 Code from B) T2 WHERE T2.CODE=T1.CODE)