SQL语句怎么查询表中的第几行的数据,比如第5行,按主键id排序。

如题
2024-11-22 23:50:54
推荐回答(5个)
回答1:

1、需要用到row_number()
2,select id,row_no
from
(select id, row_number() over( partition by 如果有需要分组的请加顷拦上,order by id ) as row_no
from table
) xx
where xx.row_no = 5
需要什么填丛乎空写什么数字就好了。渗瞎

回答2:

select id
from
(
select id
from tableA
order by id
) tab
where rownum=5

回答3:

Maybe you can try it below by yourself :
select *
from table
where count (id)=5

If it doesn't work for you, can you tell me the right answer to the question you have got and tried ??
Thanks!!!

回答4:

select top 1 * from
(select top 5 * from table order by id) order by id desc

回答5:

select top 5 * from tb where id not in (select top 4 id from tb order by id)
order by id