1、通过rownum对数据库的记录进行编号
SELECT ROWNUM RN1,A.* FROM A//从表A中获取记录,并用rownum生成RN12、通过RN1的标记进行倒序排序
SELECT B.*,ROWNUM RN2 FROM (SELECT ROWNUM RN1,A.* FROM A) ORDER BY RN1 DESC3、通过RN2取小于等于10的数据记录
SELECT * FROM (SELECT B.*,ROWNUM RN2 FROM (SELECT ROWNUM RN1,A.* FROM A) ORDER BY RN1 DESC) WHERE RN2<=101、有时间字段, 根据时间条件排序,取前十条和后十条
(1)前十条:
select * from (select * from tab_name a order by date_col )
where rownum<11
(2)后十条:
select * from (select * from tab_name a order by date_col desc)
where rownum<11
2、没有时间字段, 直接根据物理存储顺序,取前十条和后十条
(1)前十条:
select * from (select * from tab_name a order by rownum)
where rownum<11
(2)后十条:
select * from (select * from tab_name a order by rownuml desc)
where rownum<11
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)