如何倒序取出六条记录,好象order by和rownum不能同时写呀

cmjust 2004-12-15 04:00:24
倒序取出六条记录,但好象用order by和rownum不能实现我要求,该怎么写呢
...全文
224 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjliang007 2004-12-16
  • 打赏
  • 举报
回复
selec * from (selec * from b order by a desc) where rownum<7
ORARichard 2004-12-15
  • 打赏
  • 举报
回复
楼上的提醒的好啊。
ATGC 2004-12-15
  • 打赏
  • 举报
回复
SQL> select * from bb;

ID
----------
10
1
8
6
15
150
16
19

已选择8行。

SQL> select id from(
2 SELECT id,
3 row_number()
4 OVER (PARTITION BY 1
5 ORDER BY id desc NULLS LAST) top_6
6 FROM bb) b
7 where b.top_6<=6;

ID
----------
150
19
16
15
10
8

已选择6行。
epbon 2004-12-15
  • 打赏
  • 举报
回复
select * from (select rownum no,col1,col2,...,coln from tbname)
where no>(select count(0)-6 from tbname) order by no desc;
把)给弄丢了,不好意思!
epbon 2004-12-15
  • 打赏
  • 举报
回复
select * from (select rownum no,col1,col2,...,coln from tbname
where no>(select count(0)-6 from tbname) order by no desc;
ORARichard(没钱的日子好难过啊)兄可能忘了加order by :)
cmjust 2004-12-15
  • 打赏
  • 举报
回复
怎么写呀,帮我写一下好吗
ORARichard 2004-12-15
  • 打赏
  • 举报
回复
select * from (select rownum no,col1,col2,...,coln from tbname group by col1,col2,...coln)
where no>(select count(0)-6 from tbname);
snowy_howe 2004-12-15
  • 打赏
  • 举报
回复
use 分析函数

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧