select pv,a.empi from aftita_pv
,(select empi from ( select p.*,row_number() over(partition by empi order by create_time desc) rn from aftita_inpatient p) t1
where rn=1 ) a where aftita_pv.empi=a.empi
select pv,a.empi from aftita_pv
,(select empi from ( select p.*,row_number() over(partition by empi order by create_time desc) rn from aftita_inpatient p) t1
where rn=1 ) a where aftita_pv.empi=a.empi