日期:2014-05-17 浏览次数:20518 次
select top (n-m+1) id from tablename这种形式来获取指定的记录,但把id换为主码时我不知道如何操作。。。
where id not in (
select top m-1 id from tablename
)
--试试,不知道行不行
create table TableTestPrimayKey(
SNO varchar(50),
BOOKNO varchar(50),
BTIEM DATETIME,
REMARK VARCHAR(200)
)
INSERT INTO TableTestPrimayKey VALUES(NEWID(),NEWID(),GETDATE(),NEWID())
GO 100;
SELECT TOP 5 *
FROM TableTestPrimayKey
WHERE SNO NOT IN (SELECT A.SNO
FROM (SELECT TOP 10 SNO, BOOKNO
FROM TableTestPrimayKey
ORDER BY BTIEM) A
)
AND BOOKNO NOT IN (SELECT A.BOOKNO
FROM (SELECT TOP 10 SNO, BOOKNO
FROM TableTestPrimayKey
ORDER BY BTIEM) A)
;with aaa as
(
select row_number() over(order by col1,col2) as rowindex,* from table1
)
select top (n-m+1) rowindex from aaa where rowindex not in (select top m-1 from aaa)