I am trying to get First value of removed_date for individual person by using following query:
select p.person_id,
FIRST_VALUE(pe.removed_date) over (order by e.removed_date)
from person p inner join placement_episode pe on p.person_id = pe.child_id
But this is returning first non zero value for all person like shown in the output:
pid first_removed_dt
30120033 30-JAN-14
30160046 30-JAN-14
30160045 30-JAN-14
30210037 30-JAN-14
30210036 30-JAN-14
If I try to get last value using LAST_VALUE() function then its returning last value of removed date for individual person properly:
pid last_removal_date
30120033 30-JAN-14
30160046 20-AUG-14
30160045 20-AUG-14
30210037 11-FEB-15
30210036 17-FEB-15
Why FIRST_VALUE() function is behaving like this? Is there any other way by which i can get first removal_date for individual person?