日期:2014-05-17 浏览次数:20829 次
select a.aid,b3.bid
from a,
(select b1.a_rec_no,b1.bid
from b b1
where not exists (select 1
from b b2
where b1.a_rec_no = b2.a_rec_no
and b2.DATE > b1.DATE)) b3
where a.rec_no = b3.a_rec_no
WITH table1 AS
(
SELECT '1000' AS REC_NO, 'aaa' AS AID FROM dual
),
table2 AS
(
SELECT '2000' AS REC_NO, '1000' AS A_REC_NO,'bbb' AS BID,'10/10/2012' AS DD FROM dual
union all
SELECT '2001' AS REC_NO, '1000' AS A_REC_NO,'ccc' AS BID,'11/10/2012' AS DD FROM dual
union all
SELECT '2002' AS REC_NO, '5000' AS A_REC_NO,'ddd' AS BID,'15/10/2012' AS DD FROM dual
)
SELECT AID,BID FROM(
SELECT * FROM TABLE2 T2 INNER JOIN TABLE1 T1 ON T2.A_REC_NO = T1.REC_NO ORDER BY DD DESC) WHERE ROWNUM = 1
WITH table1 AS
(
SELECT '1000' AS REC_NO, 'aaa' AS AID FROM dual
union all
SELECT '1001' AS REC_NO, 'yyy' AS AID FROM dual
),
table2 AS
(
SELECT '2000' AS REC_NO, '1000' AS A_REC_NO,'bbb' AS