oracle 查询数据只要排序后的第一条记录(不用rownum=1),sql语句怎么写

如题所述

第1个回答  2022-11-16

1、创建测试表,

create table test_order(id number, value varchar2(50));

2、插入测试数据

insert into test_order values(3,'v3');

insert into test_order values(2,'v2');

insert into test_order values(1,'v1');

insert into test_order values(5,'v5');

insert into test_order values(4,'v4');

commit;

3、查询表中全量数据,可以发现数据并未排序,select t.*, rowid from test_order t;

4、编写sql,数据只要排序后的第一条记录(不用rownum=1) select * from (select t.*, row_number() over(order by id) rn from test_order t) t where rn = 1;

相似回答