几个关于取从第一行到第几行数据

时间:2021-10-18 15:04:27

select top 5 ID from ActionInfo where ID not in (select top 20 ID from ActionInfo order by ID) order by ID

select top 5 ID from ActionInfo where not exists (select * from (select top 20 ID from ActionInfo order by ID) a where a.ID=ActionInfo.ID ) order by ID

select 1 from (select top 20 ID from ActionInfo order by ID) as aa --where aa.ID=[OADB].[dbo].[ActionInfo].ID

select top 5 ID from ActionInfo where ID > (select max(ID) from (select top 20 ID from ActionInfo order by ID) a ) order by ID

select top 5 ID from ( select row_number() over (order by ID) as rownumber,* from ActionInfo ) a where rownumber > 20 order by ID

WITH sss AS(
SELECT *,ROW_NUMBER() OVER(ORDER BY ID) AS rowNum FROM ActionInfo
)
SELECT * FROM sss WHERE rowNum BETWEEN 11 AND 20