0

我是编码新手,正在准备一个 SQL 命令,但卡在了一步。下面是主要的 SQL 查询:

select 
distinct 
hap.position_code as RequisitionNumber, 
COALESCE(hap.attribute10,'UNIVERSAL') as RequisitionType, hap.name as 
RequisitionTitle, 
paam1.job_id as RequisitionTemplate, COALESCE(hap.attribute11,'1') as 
NumberToHire, 

pu.username as HiringManagerLogin, 

paam1.job_id as JobField, 
hap.full_part_time as Schedules, hap.position_code as PositionCode  
from hr_all_positions hap, per_all_assignments_m paam1, per_users pu 
where hap.position_id = paam1.position_id
and hap.position_id in
(
select distinct paam.position_id from per_all_assignments_m paam, 
per_periods_of_service ppos 
where paam.person_id = ppos.person_id and paam.position_id is not null and 
ppos.actual_termination_date >= sysdate
)

在上面的查询中,我从下面附加的另一个查询中获取 pu.username 的值:

select pu.username from per_users pu where person_id = (
select pmhd.manager_id from PER_MANAGER_HRCHY_DN pmhd, 
per_periods_of_service ppos 
where pmhd.person_id = ppos.person_id and pmhd.IMMEDIATE_REPORTEE_ASG_ID is 
not null 
and pmhd.EFFECTIVE_END_DATE = ppos.actual_termination_date and 
ppos.actual_termination_date >= sysdate 
and pmhd.person_id = (select distinct paam.person_id from 
per_all_assignments_m paam, per_periods_of_service ppos 
where paam.person_id = ppos.person_id and paam.position_id is not null and 
ppos.actual_termination_date >= sysdate) 
)

现在,当我加入两个查询时,如下所示:

select 
distinct 
hap.position_code as RequisitionNumber, 
COALESCE(hap.attribute10,'UNIVERSAL') as 
RequisitionType, hap.name as RequisitionTitle, 
paam1.job_id as RequisitionTemplate, COALESCE(hap.attribute11,'1') as 
NumberToHire, 

pu.username as HiringManagerLogin, 

paam1.job_id as JobField, 
hap.full_part_time as Schedules, hap.position_code as PositionCode  
from hr_all_positions hap, per_all_assignments_m paam1, per_users pu 
where hap.position_id = paam1.position_id and paam1.person_id = pu.person_id
and pu.person_id = (
select pmhd.manager_id from PER_MANAGER_HRCHY_DN pmhd, per_periods_of_service 
ppos 
where pmhd.person_id = ppos.person_id and pmhd.IMMEDIATE_REPORTEE_ASG_ID is 
not null 
and pmhd.EFFECTIVE_END_DATE = ppos.actual_termination_date and 
ppos.actual_termination_date >= sysdate 
and pmhd.person_id = (select distinct paam.person_id from 
per_all_assignments_m 
paam, per_periods_of_service ppos 
where paam.person_id = ppos.person_id and paam.position_id is not null and 
ppos.actual_termination_date >= sysdate) 
)
and hap.position_id in
(
select distinct paam.position_id from per_all_assignments_m paam, 
per_periods_of_service ppos 
where paam.person_id = ppos.person_id and paam.position_id is not null and 
ppos.actual_termination_date >= sysdate
)

我正在尝试这是Oracle 数据库 没有数据输出来了,我不明白为什么?

请帮我 !!

在此先感谢, 希瓦姆

4

1 回答 1

1

老实说,您的最终查询输出看起来像是其他两者的适当组合。但是,由于附加的连接条件,您可能不会得到任何输出:

paam1.person_id = pu.person_id

This is not in either of your original queries, and every row probably fails this join condition. Try removing it to see if any rows are output. Try adding it to your first query. If rows are output, then it probably means that your additional filter on pu.person_id is very selective.

于 2018-08-14T20:42:35.487 回答