我有一张表,我需要检索第二行的ID.如何实现呢?
按顶部2我选择两个第一行,但我只需要第二行
解决方法
假设sql Server 2005是一个如何获得第二行的例子(我认为你可能会问 – 这是为什么顶部不适合你的原因?)
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