0

Per_all_people_f

name  person_id  emp_flag  effective_start_date   effective_end_date   DOJ
--------------------------------------------------------------------------------    
ABC   123          Y       30-MAR-2011              30-MAR-2013       10-FEB-2011
ABC   123          Y       24-FEB-2011              27-FEB-2011       10-FEB-2011
DEF   345          N       10-APR-2012              30-DEC-4712       15-SEP-2011

per_chcklist

 person_id   name
  ------------------   
123         C1
456         C2 
345         C3 

ACTUAL_TERMINATION_DATE

person_id   TERM_DATE
      ------------------   
    123         30-SEP-2013
    456         30-AUG-2013
    345         29-AUG-2013

现在我想计算所有那些在 Per_all_people_f 中并且其 TERM_DATE 存在于 ACTUAL_TERMINATION_DATE 但不在 per_chcklist 中的人 ID。

我想在查询中使用简单的不存在。我写的查询是:-

select papf.person_id,
papf.name
from per_all_people_f papf,
per_chcklist pc,
ACTUAL_TERMINATION_DATE atd

where papf.person_id=atd.person_id
and atd.TERM_DATE is not null
and pc.person_is!=papf.person_id;

但这并没有给我答案。

4

1 回答 1

0

我可能会建议您使用existsand编写此查询not exists。它更符合您的要求:

select papf.person_id, papf.name
from per_all_people_f papf
where exists (select 1
              from ACTUAL_TERMINATION_DATE atd
              where atd.TERM_DATE = papf.TERM_DATE and atd.person_id = papf.person_id
             ) and
      not exists (select 1
                  from per_chcklist pc
                  where papf.person_id = pc.person_id
                 );

完成这项工作后,如果您想了解有关连接的更多信息,您可以弄清楚如何将其表示为显式连接。

于 2013-08-30T18:05:53.017 回答