你这SQL语句什么也查不到--SELECT TOP 5 * FROM table WHERE NOT exists (SELECT TOP 10 id FROM table)
go if OBJECT_ID('test')is not null drop table test go create table test( id int identity(1,1), value int ) go declare @b int set @b=1 while @b<100 begin insert test select @b set @b=@b+1 end SELECT TOP 5 * FROM test WHERE (id NOT IN (SELECT TOP 15 id FROM test)) /* id value 16 16 17 17 18 18 19 19 20 20 */
SELECT TOP 5 * FROM test b WHERE not exists(select 1 from(select top 15 id from test)a where b.id<=a.id) /* id value 16 16 17 17 18 18 19 19 20 20 */
go if OBJECT_ID('test')is not null drop table test go create table test( id int identity(1,1), value int ) go declare @b int set @b=1 while @b<100 begin insert test select @b set @b=@b+1 end SELECT TOP 5 * FROM test WHERE (id NOT IN (SELECT TOP 10 id FROM test)) /* id value 16 16 17 17 18 18 19 19 20 20 */--他的语句能实现,你是不是没测试数据啊
SELECT TOP 5 * FROM table WHERE (id NOT IN (SELECT TOP 10 id FROM table))SELECT TOP 5 * FROM test b WHERE not exists(select 1 from(select top 15 id from test)a where b.id<=a.id)哪位能分析下效率不???
select top * from table where id not in (select id from table )
FROM table
WHERE NOT exists
(SELECT TOP 10 id
FROM table)
go
if OBJECT_ID('test')is not null
drop table test
go
create table test(
id int identity(1,1),
value int
)
go
declare @b int
set @b=1
while @b<100
begin
insert test
select @b
set @b=@b+1
end
SELECT TOP 5 *
FROM test
WHERE (id NOT IN
(SELECT TOP 15 id
FROM test))
/*
id value
16 16
17 17
18 18
19 19
20 20
*/
SELECT TOP 5 *
FROM test b
WHERE not exists(select 1 from(select top 15 id from test)a where b.id<=a.id)
/*
id value
16 16
17 17
18 18
19 19
20 20
*/
go
if OBJECT_ID('test')is not null
drop table test
go
create table test(
id int identity(1,1),
value int
)
go
declare @b int
set @b=1
while @b<100
begin
insert test
select @b
set @b=@b+1
end
SELECT TOP 5 *
FROM test
WHERE (id NOT IN
(SELECT TOP 10 id
FROM test))
/*
id value
16 16
17 17
18 18
19 19
20 20
*/--他的语句能实现,你是不是没测试数据啊
FROM table
WHERE (id NOT IN
(SELECT TOP 10 id
FROM table))SELECT TOP 5 *
FROM test b
WHERE not exists(select 1 from(select top 15 id from test)a where b.id<=a.id)哪位能分析下效率不???