왜 AI_CL_ID = 111에 대한 두 행이 맞습니까? 기록 된 = 123은 '괴물'에 해당하지만 귀하의 target_system
테이블에는 '2 차'가 있으므로 사양에 따라 잘못되었습니다.
target_system
테이블의 모든 행이 잘못된 op_code
인 경우 다음 쿼리를 사용할 수 있습니다. 가정 : 쌍 (id, code)은 유일하다 target_system
; 어떤 열에도 NULL이 없습니다. source_name
의 target_system
은 항상 정확합니다 (일치하는 경우 id
및 code
일 때 source_name
은 source_system
과 일치 함). 마커 'Primary'
은 특별하지만 'Secondary'
외에 다른 마커가있을 수 있습니다.
target_system
의 정의 이후 솔루션에 "with"에서 "close"까지의 행이 포함되지 않습니다. WITH 절은 쿼리 자체 내에서 테스트 데이터를 생성하는 데 사용되지만 실제로는 select t.id, ...
으로 시작하고 기본 테이블이나 뷰를 히트해야합니다.
with
source_system (id, code, source_id, source_name) as (
select 123, 111, 'Monster', 'Dice.com' from dual union all
select 456, 111, 'Dice' , 'ABC COMPANY' from dual union all
select 456, 888, 'Ticv' , 'A2 systems' from dual union all
select 4566, 999, 'MOnster', 'hgtt solutions' from dual union all
select 789, 222, 'Monster', 'ABC COMPANY' from dual union all
select 985, 222, 'Dice' , 'Dice.com' from dual
),
target_system (recordid, ai_cl_id, source_name, op_code) AS (
select 123, 111, 'Dice.com' , 'Secondary' from dual union all
select 456, 111, 'ABC COMPANY', 'Primary' from dual union all
select 789, 222, 'ABC COMPANY', 'Secondary' from dual union all
select 985, 222, 'Dice.com' , 'Primary' from dual
)
select t.recordid, t.ai_cl_id, t.source_name, t.op_code
from target_system t inner join source_system s
on t.recordid = s.id and t.ai_cl_id = s.code
where (s.source_id = 'Monster' and t.op_code != 'Primary')
or
(s.source_id != 'Monster' and t.op_code = 'Primary')
order by ai_cl_id, recordid
;
출력 (사용자의 입력에, 나는 설명 된대로 출력이 당신이 게시물에 무슨 이후 게시물이 다른은 잘못된 것입니다).
RECORDID AI_CL_ID SOURCE_NAME OP_CODE
---------- ---------- ----------- ---------
123 111 Dice.com Secondary
456 111 ABC COMPANY Primary
789 222 ABC COMPANY Secondary
985 222 Dice.com Primary
귀하의 질문에 명확하지 않으며 다른 독자들도 같은 방식으로 생각할 수 있습니다. 달성하고자하는 것을 더 잘 설명하십시오. – Elyasin