我有两个选择查询,其中查询 A 包含所有数据,另一个查询包含一些数据。我们需要从两条查询记录中获取不常见的数据。比方说(查询 A - 查询 B)。
请查找以下示例,其中包含现有数据和预期输出。
查询A:
SELECT meaning
FROM apps.fnd_lookup_values
WHERE lookup_type = 'XXLSC_SCHEDULE_PRO_LKP';
查询A的输出:
意义 |
---|
自动发票导入程序 |
清除并发请求和/或管理器数据 |
创建公司间 AP 发票 |
汇总累计提前期 |
记录订单管理交易 |
查询B:
SELECT DISTINCT fcs.program
FROM apps.fnd_concurrent_requests fcr,
apps.fnd_concurrent_programs_tl fcp,
apps.fnd_responsibility_tl frl,
apps.fnd_user fu,
apps.fnd_conc_req_summary_v fcs
WHERE fcr.phase_code = 'P'
AND fcr.request_id = fcs.request_id
AND frl.language = 'US'
AND fcr.requested_by = fu.user_id
AND fcr.responsibility_id = frl.responsibility_id
AND fcr.status_code IN ('P','Q')
AND fcp.language = 'US'
AND fcp.source_lang = 'US'
AND fcr.concurrent_program_id = fcp.concurrent_program_id
AND fcr.requested_start_date >= SYSDATE
AND fcs.program IN (SELECT meaning FROM apps.fnd_lookup_values
WHERE lookup_type = 'XXLSC_SCHEDULE_PRO_LKP');
查询B的输出:
节目 |
---|
自动发票导入程序 |
创建公司间 AP 发票 |
记录订单管理交易 |
下面是最终的预期输出(从两个查询中获取不常见的数据 - 查询 A 的所有数据将从查询 B 记录中减去):
意义 |
---|
清除并发请求和/或管理器数据 |
汇总累计提前期 |
可以通过
INNER JOIN
/OUTER JOIN
/EXPECT
/UNION
或其他方式实现吗?
如果有人能就此问题向我提出疑问,我将不胜感激。因为我的一个项目需要这样做。
谢谢!
“查询 A - 查询 B”实际上是一个很好的描述方式,因为 Oracle 有一个
minus
集合运算符:
SELECT meaning -- This is query A
FROM apps.fnd_lookup_values
WHERE lookup_type = 'XXLSC_SCHEDULE_PRO_LKP';
MINUS -- Set operator here
SELECT fcs.program -- This is query B, with the DISTINCT modifier removed
FROM apps.fnd_concurrent_requests fcr,
apps.fnd_concurrent_programs_tl fcp,
apps.fnd_responsibility_tl frl,
apps.fnd_user fu,
apps.fnd_conc_req_summary_v fcs
WHERE fcr.phase_code = 'P'
AND fcr.request_id = fcs.request_id
AND frl.language = 'US'
AND fcr.requested_by = fu.user_id
AND fcr.responsibility_id = frl.responsibility_id
AND fcr.status_code IN ('P','Q')
AND fcp.language = 'US'
AND fcp.source_lang = 'US'
AND fcr.concurrent_program_id = fcp.concurrent_program_id
AND fcr.requested_start_date >= SYSDATE
AND fcs.program IN (SELECT meaning FROM apps.fnd_lookup_values
WHERE lookup_type = 'XXLSC_SCHEDULE_PRO_LKP');