欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取某一行数据

程序员文章站 2022-03-20 19:23:36
比如: DECLARE @t AS TABLE([Datas] NVARCHAR(40)) INSERT INTO @t ([Datas]) VALUES(N'DF'),(N'W4F'),(N'EYY'),(N'ER'),(N'GFF'),(N'A445') SELECT [Datas] FROM ......

比如:

 

declare @t as table([datas] nvarchar(40))
insert into @t ([datas]) values(n'df'),(n'w4f'),(n'eyy'),(n'er'),(n'gff'),(n'a445')

select [datas] from @t order by [datas]

 

由于我们不清楚datas数据内容,它是动态的内容。但是我们需要获取这表中的某一笔记录,那如何获取呢?

可以使用row_number方法来求得:

 

select [datas] from (
    select row_number() over (order by [datas]) as [rownumber], [datas] from @t) as t
where [rownumber] in (2,5)