Sql ve两条记录。@user3014914:在这种情况下,您可能必须将计算更改为(按ass.person\u id,ass.effective\u start\u date划分)这对我帮助很大,它给了我一个想法,让我想出一个更好的解决方案,谢谢!@user30
Sql ve两条记录。@user3014914:在这种情况下,您可能必须将计算更改为(按ass.person\u id,ass.effective\u start\u date划分)这对我帮助很大,它给了我一个想法,让我想出一个更好的解决方案,谢谢!@user30,sql,oracle,join,Sql,Oracle,Join,ve两条记录。@user3014914:在这种情况下,您可能必须将计算更改为(按ass.person\u id,ass.effective\u start\u date划分)这对我帮助很大,它给了我一个想法,让我想出一个更好的解决方案,谢谢!@user3014914:您能为这个问题添加您的解决方案吗? select ass.person_id, ass.effective_start_date, ass.effective_end_date, exp.date
ve两条记录。@user3014914:在这种情况下,您可能必须将计算更改为
(按ass.person\u id,ass.effective\u start\u date划分)
这对我帮助很大,它给了我一个想法,让我想出一个更好的解决方案,谢谢!@user3014914:您能为这个问题添加您的解决方案吗?
select
ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country
from expatriates exp, assignments ass
where
exp.person_id=ass.person_id
and exp.date_to >= ass.effective_start_date
and exp.date_to <= ass.effective_end_date
select
distinct ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country
from expatriates exp, assignments ass
where
exp.person_id=ass.person_id
and exp.date_to >= ass.effective_start_date
and exp.date_from <= ass.effective_end_date
select
ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country
from expatriates exp, assignments ass
where
exp.person_id=ass.person_id
and exp.date_to >= ass.effective_start_date
and exp.date_from <= ass.effective_end_date
and exp.status = 1
select
ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country
from expatriates exp, assignments ass, (
SELECT e.person_id, MAX(e.date_from) md
FROM expatriates e
INNER JOIN assignments a ON e.person_id=a.person_id
and e.date_to >= a.effective_start_date
and e.date_to <= a.effective_end_date GROUP BY e.person_id) X
where exp.person_id= X.person_id
and exp.date_from= X.md
active_or_last_ass AS (
SELECT exp.person_id, date_from, max(exp.date_to) max_date
FROM expatriates exp
WHERE exp.date_from < sysdate
GROUP BY exp.person_id, date_from
)
select
ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country
from
active_or_last_ass ala
inner join expatriates exp
on exp.person_id = ala.person_id
and exp.date_to = ala.max_date
inner join assignments ass
on exp.person_id = ass.person_id
select *
from
(
select
ass.person_id,
ass.effective_start_date,
ass.effective_end_date,
exp.date_from,
exp.date_to,
exp.home_country,
exp.host_country,
row_number()
over (partition by ass.person_id, ass.effective_start_date
order by exp.date_from) as rn
from expatriates exp, assignments ass
where
exp.person_id=ass.person_id
and exp.date_to >= ass.effective_start_date
and exp.date_to <= ass.effective_end_date
) dt
where rn = 1