获取第n行数据

来源:互联网 发布:辐射4赵船长 知乎 编辑:程序博客网 时间:2024/05/21 15:07

set nocount on
--建立测试环境并插入数据,并且表没有主键
create table test(id int ,name varchar(10))
insert into test select 999,'jinjazz'  
insert into test select 888,'csdn'
insert into test select 999,'sqlserver'

--通过游标获取绝对行数
declare myCursor scroll  cursor for select * from  test
open myCursor
fetch  absolute  3  from  myCursor
close myCursor
deallocate myCursor

--删除测试环境
drop table test
set nocount off

 

 

declare @t table(id int ,name varchar(10))
insert into @t select 999,'jinjazz'  
insert into @t select 888,'csdn'
insert into @t select 999,'sqlserver'

select top 1 * from
(
select top 3 * from @t order by id desc)t

原创粉丝点击