T-SQL 如何从表中只选择第二行? [英] T-SQL How to select only Second row from a table?
本文介绍了T-SQL 如何从表中只选择第二行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张表,我需要检索第二行的 ID.如何实现?
I have a table and I need to retrieve the ID of the Second row. How to achieve that ?
By Top 2
我选择了前两行,但我需要只第二行
By Top 2
I select the two first rows, but I need only the second row
推荐答案
假设 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
这篇关于T-SQL 如何从表中只选择第二行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文