Retrieving the employees Rehired within a year from their termination date in peoplesoft/oracle sql? -
i have table-
empl id eff seq emp name date action 20140531 1 abc 05-may-08 hired 20140531 1 abc 05-jun-08 termin 20140531 1 abc 15-dec-08 rehired 20158888 1 xyz 25-jan-10 hired 20158888 1 xyz 05-may-10 termin 20156666 1 bbb 12-feb-12 hired 20157777 1 aaa 05-may-13 hired
so if write query on above database, should return emplid-
- 20140531
as employee rehired within year termination date. wondering how can results.
assuming table defined as
create table empls(emplid number, eff_seq number, emp_name varchar2(10), action_date date, action varchar2(10));
and populated data specified in question following query you're looking for:
with rehired_empls (select * empls action = 'rehired'), terminated_empls (select * empls action = 'termin') select distinct r.emplid rehired_empls r inner join terminated_empls t on t.emplid = r.emplid t.action_date between r.action_date - interval '1' year , r.action_date;
best of luck.
edit
updated query , sqlfiddle based on corrected data provided op.
Comments
Post a Comment