oracle多表关联查询 在Oracle中怎样查询前10条记录?
在Oracle中怎样查询前10条记录?根据时间条件排序,取前十条和后十条。1、有时间字段, 根据时间条件排序,取前十条和后十条(1)前十条:select * from (select * from t
在Oracle中怎样查询前10条记录?
根据时间条件排序,取前十条和后十条。
1、有时间字段, 根据时间条件排序,取前十条和后十条
(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
oracle表中有很多相同的记录,怎么只取满足条件的第一条?
oracle只取满足条件的n条记录,和SQL server写法不一样,要使用关键字rownum。
如果只取1条记录:select 列名 from 表名 where rownum=1
如果想取前5条记录:select 列名 from 表名 where rownum>=5