34,576
社区成员
发帖
与我相关
我的任务
分享
SELECT TOP 5 *
FROM table
WHERE (id NOT IN
(SELECT TOP 10 id
FROM table))
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)
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
*/
--他的语句能实现,你是不是没测试数据啊
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
*/
--
SELECT TOP 5 *
FROM table
WHERE NOT exists
(SELECT TOP 10 id
FROM table)