请教一条oracle语句
假设A表是一个员工表,B表为履历表,其中有一个字段B_Order为履历信息的顺序。
请问能否用一条sql语句找出A表中所有员工信息及B表中对应的最新的一条履历信息。
既用关联语句select * from A a,B b where a.id=b.id and .....
B表出来的只是一个人的最新的那条,既B_Order为最大值的那条。
------解决方案--------------------用max函数分组。
------解决方案--------------------SELECT A.*
FROM A
INNER JOIN (
SELECT FIRST_VALUE(B_Order) OVER (PARTITION BY ID ORDER BY B_Order DESC) AS MAX_B_Order,
ID
FROM B
) ON A.ID = B.ID AND B.MAX_B_Order = B.ID;
------解决方案--------------------select *
from A a,B b
where a.id=b.id
and b.B_Order||b.id =
(select max(B_Order)||id from B group by id) ;
或者
select *
from A a,B b
where a.id=b.id
and (b.B_Order,b.id) in
(select max(B_Order),id from B group by id) ;