oracle 怎么查最后100行数据

luck5 2005-11-16 02:52:20
from tablea where rownum<100
这是取前100行,可如何取出最后的100行,
...全文
2124 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ygc8163 2005-11-17
  • 打赏
  • 举报
回复
select * from tablename where rowid in (select rowid from tablename where rownum <=100 order by rowid desc) order by rowid asc

tablename 为表名,
rowid 换成你表中用于排序的关键字
rownum 是oracle内置的关键字,用于查询多少条纪录
ygc8163 2005-11-17
  • 打赏
  • 举报
回复
select * from tablename where rowid in (select rowid from tablename where rownum <=100 order by rowid desc) order by rowid asc
pobaby 2005-11-17
  • 打赏
  • 举报
回复
select * from ( select * from table a order by rowid desc) where rownum<=10;
luck5 2005-11-17
  • 打赏
  • 举报
回复
这样显示的数据是倒顺序的
wgsasd311 2005-11-16
  • 打赏
  • 举报
回复 1
select * from
(select * from tb order by rownum desc)
where rownum<100;
Hangfeng 2005-11-16
  • 打赏
  • 举报
回复
上面错了,应该是
select * from
(select rownum rn,a.* from table a order by rn desc)
where rownum<=100
Hangfeng 2005-11-16
  • 打赏
  • 举报
回复
select * from
(select rowid id,a.* from table a order by id desc)
where rownum<=100
超叔csdn 2005-11-16
  • 打赏
  • 举报
回复
select a.* from
(select tablea.*,rownum r from tablea ) a,(select count(*) as cn from tablea) b
where a.r<=b.cn and a.r>b.cn-100

17,377

社区成员

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

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