I have created following select:
select e.first_name, e.last_name,
(select jobname_id from
(select j.id, j.jobname_id, first_value(j.jobname_id)
over (order by j.date_from desc) as current_job
from jobs j where j.emp_id=e.emp_id and j.date_from < sysdate)
where jobname_id != current_job and rownum=1) as previous_job
from employees e
but I get “ORA-00904: “E”.”EMP_ID”: invalid identifier”
how can I use the reference to E.EMP_ID in the subquery?
I don’t know if this solution ist fast enough for your needs but it should work as planned.
Also, I agree with Ollie about the additional field “date_to”. It would make things easier.