17,377
社区成员
发帖
与我相关
我的任务
分享
SQL>
SQL> create table test(
2 DMED_NO varchar(10),
3 DREGNO varchar(10),
4 DTIMES varchar(10),
5 DTELL varchar(10),
6 DMED_REC varchar(10)
7 );
Table created
SQL> begin
2 insert into test values('00190772', '1612300463', 1, '左手扭X', '空');
3 insert into test values('00190772', '1612300463', 2, '左手。', '空');
4 insert into test values('00036192', '1612310107', 1, '后9天', '外');
5 insert into test values('00036192', '1612310107', 2, '9天', ' f,');
6 end;
7 /
PL/SQL procedure successfully completed
SQL> with m as (
2 select t.*,
3 row_number() over(partition by dregno order by dtimes desc) rn
4 from test t
5 )
6 select * from m where rn =1 ;
DMED_NO DREGNO DTIMES DTELL DMED_REC RN
---------- ---------- ---------- ---------- ---------- ----------
00036192 1612310107 2 9天 f, 1
00190772 1612300463 2 左手。 空 1
SQL> drop table test purge;
Table dropped
SQL>