--Oracle表里 同個人有五條數據 ,取出id值最大的那條數據: --1:創建表: create table a(id number(20) ,name varchar2(300) ) ; create table b(id number(20) ,fenshu varchar2(300),a_id number(20) ,kemu varchar2(300) ) ; --2:插入數據 insert into a (ID, NAME) values (1, 'A'); insert into b (ID, FENSHU, A_ID, KEMU) values (1, '45', 1, 'yw'); insert into b (ID, FENSHU, A_ID, KEMU) values (2, '56', 1, 'sx'); insert into b (ID, FENSHU, A_ID, KEMU) values (3, '67', 1, 'hx'); --3:查詢數據 select * from a ;
select * from b ;
--4:查詢最大值數據 select * from (select t.*, --降序 max最先 row_number() over(partition by t.a_id order by t.id desc) rn from b t) c where rn = 1; select * from b ;



