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

如题
2024年11月22日 23:50
有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