oracle - Sql query to fetch minimun date start against each employee -
i have 2 table asg
, work rship
in work rship table there date_start
each employee. few employee date_start duplicate have choose min(date_start)
work rship table
for wrote query :
select assignment_name, regexp_substr(assignment_name, '[0-9]+') person_number, nvl( wrk.date_start,t.effective_start_date) , nvl( wrk.worker_type,'e'), nvl( wrk.legal_employer_name, 'n/a') (select apps.assignment_table.*, count(*) on (partition assignment_name, effective_start_date, effective_end_date, effective_latest_change) c apps.assignment_table ) t left outer join (select * apps.work_table date_start = (select min(date_start) apps.work_table ) ) wrk on regexp_substr(t.assignment_name, '[0-9]+')=wrk.person_number c =1;
but in above query did mistake of selecting select min(date_start) apps.work_table means min(date_start) entire table. instead of should have included regexp_substr(t.assignment_name, '[0-9]+')=wrk.person_number
inside inline query itself.
but when including it.. not working. can point out erroe.
left outer join (select * apps.work_table date_start = (select min(date_start) apps.work_table ) ) wrk on
unless start_date
person minimum value across people in entire table (and not minimum date person) code above not find rows match person want.
what meant like:
left outer join ( select * ( select t.*, row_number() on ( partition person_number order date_start asc ) rn apps.work_table t ) rn = 1 ) wrk on
Comments
Post a Comment