Take the first 20 to 30 queries as an example. The primary key name is id.
Method 1: perform a regular check first and then perform a reverse check.
Select top 10 * from (select top 30 * from tablename order by id asc) A order by id desc
Method 2: Use left join
Select top 10 A. * from tablename
Left outer join (select top 20 * from tablename order by id asc) B
On A. id = B. id
Where B. id is null
Order by A. id asc
Method 3: Use not exists
Select top 10 * from tablename
Where id not exists
(Select top 20 * from tablename B on A. id = B. id)
Method 4: Use not in
Select top 10 * from tablename
Where id not in
(Select top 20 id from tablename order by id asc)
Order by id asc
Method 5: Use rank ()
Select id from
(Select rank () over (order by id asc) rk, id from tablename) T
Where rk between 20 and 30
In the fifth method, it seems that there is no problem. I checked the document below. When over () is used for rank/row_number, the integer Column cannot describe a column, so it will produce unexpected results. to be considered, is there any way to change it to the desired result.