比较简单的方法就是这样select * from table1 a1
left join table2 a2 on a1.planid=a2.palnid
where col1= (select min(col1) from table2 where a2.palnid=palnid)/*col1 时间字段*/
left join table2 a2 on a1.planid=a2.palnid
where col1= (select min(col1) from table2 where a2.palnid=palnid)/*col1 时间字段*/
with table1 as(
select 1 planid,'2' tt from dual union all
select 3,'' from dual union all
select 4,'' from dual union all
select 2,'' from dual ),
table2 as(
select 1 planid,4 时间 from dual union all
select 1,5 from dual union all
select 2,4 from dual union all
select 4,4 from dual)
select *
from table1 a1,
(select *
from table2 a2
where a2.时间 =
(select max(时间) from table2 k where k.planid = a2.planid)) a3
where a1.planid = a3.planid(+)
select 1 planid,'2' tt from dual union all
select 3,'3' from dual union all
select 4,'4' from dual union all
select 2,'2' from dual ),
table2 as(
select 1 planid,4 时间 from dual union all
select 1,5 from dual union all
select 2,4 from dual union all
select 2,6 from dual)
select * from (select * from table2 A WHERE A.时间=(select max(时间)
FROM TABLE2 B WHERE B.PLANID=A.PLANID)) C join table1 D on c.planid=d.planid