且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

T-SQL 如何从表中只选择第二行?

更新时间:2023-02-06 10:47:46

假设 SQL Server 2005+ 是如何获得只是第二行的示例(我想您可能会问 - 而且是top 对你不起作用的原因是什么?)

Assuming SQL Server 2005+ an example of how to get just the second row (which I think you may be asking - and is the reason why top won't work for you?)

set statistics io on

;with cte as
(
  select *
    , ROW_NUMBER() over (order by number) as rn
  from master.dbo.spt_values
) 
select *
from cte
where rn = 2

/* Just to add in what I was running RE: Comments */
;with cte as
(
  select top 2 *
    , ROW_NUMBER() over (order by number) as rn
  from master.dbo.spt_values
) 
select *
from cte
where rn = 2