日期:2014-05-17 浏览次数:20844 次
with temp1(login_id,name,post_name) as( select 1,'张三','java' from dual union all select 2,'李四','.net' from dual ), temp2(login_id,name,pro_post_name,result,"desc",time) as( select '1','张三','java',1,'desc1',to_date('2012-05-12','yyyy-mm-dd') from dual union all select '1','张三','java',2,'desc2',to_date('2012-06-05','yyyy-mm-dd') from dual union all select '2','李四','java',2,'desc3',to_date('2012-05-22','yyyy-mm-dd') from dual union all select '2','李四','.net',2,'desc4',to_date('2012-05-12','yyyy-mm-dd') from dual ) select a.login_id,a.name,a.post_name,b.result,b."desc" from temp1 a inner join temp2 b on a.login_id=b.login_id and a.post_name=b.pro_post_name and b.time=(select max(time) from temp2 c where c.login_id=b.login_id and c.pro_post_name=b.pro_post_name); /* LOGIN_ID NAME POST_NAM RESULT desc ---------- ------------ -------- ---------- ---------- 1 张三 java 2 desc2 2 李四 .net 2 desc4 */