
Originally Posted by
indira.s
Hi,
The answer provided with LEAD and OVER gives you the difference between only successive employees.
If the question is to get difference between all employees, then its better to use a cross join and get difference between hire_dates:
select hire_date,startdate,(hire_date-startdate) diff
from employees e,
(select employee_id,hire_date startdate from employees) d
where e.employee_id<>d.employee_id;
Or, if its to get the difference between 2 specified dates:
select hire_date,startdate,
round(months_between(startdate,hire_date)) MonthsBetw
from employees,(select hire_date startdate from employees
where employee_id=&empid1)
where employee_id=&empid2;
Bye.