SQL,从表中选择Nth到Mth记录,哪个查询更有效?

pri*_*e23 0 sql-server

面试问题:

编写SQL Server查询以返回表A的第30到第40条记录

我的答案:

select top 10 * from (select top 40 * from tb desc) asc

select top 40 * from A where id not in(select top 30 id from A) 
Run Code Online (Sandbox Code Playgroud)

以上哪个更有效率?为什么?

Jam*_*ong 6

不要使用其中任何一个,你可以直接选择那些30-40行

请参阅:SQL Server中的行偏移