sql 先筛选后排序再获取指定行记录
答案:2 悬赏:20 手机版
解决时间 2021-02-23 00:22
- 提问者网友:川水往事
- 2021-02-22 17:58
sql 先筛选后排序再获取指定行记录
最佳答案
- 五星知识达人网友:不如潦草
- 2021-02-22 19:05
比较一般性的查询方法, 用row_number() over(partition by ... order by ...)先给记录按na列的值分组排序(按no降序),然后取出编号值为3~6的记录即可.
select s.*
from (
select d.no, d.na, d.nb, row_number() over(partition by na order by no desc) as idx
from table_name d
where na = 'a'
) s
where s.idx >= 3 and s.idx <= 6
select s.*
from (
select d.no, d.na, d.nb, row_number() over(partition by na order by no desc) as idx
from table_name d
where na = 'a'
) s
where s.idx >= 3 and s.idx <= 6
全部回答
- 1楼网友:从此江山别
- 2021-02-22 19:20
select * from 表名 where na=‘a’ order by no desc having rownum between 3 and 6;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯