Table 두개가 있습니다.
두 개의 테이블에는 같은 값들이 들어가 있으나
한 테이블에만 있는 값이 있습니다.
저는 이러한 값들을 모두 Select해서 화면에 나타내 주고 싶습니다.
화면에는 두 테이블의 값들을 각각 뿌려 주고
두 테이블에 모두 있는 값들은 모두 나타내어 주고
한 테이블에만 있는 값은 있는 테이블 값에만 나타내어 주고 없는 테이블 값에는 빈칸으로 화면에 나타내고 싶습니다.
Row_number () over partition ... 이걸 사용해야 할까요?
아니면 rownum을 이용해서 해야 하는걸까요?
여러가지 방법을 해 보다가 안되서 이렇게 도움을 요청합니다 ㅠㅠ
제 설명이 애매해서 파일을 첨부하여 올렸습니다.
with a as ( select 'a' name from dual union all select 'b' from dual union all select 'c' from dual union all select 'e' from dual union all select 'f' from dual union all select 'g' from dual union all select 'h' from dual ), b as ( select 'a' name from dual union all select 'b' from dual union all select 'c' from dual union all select 'd' from dual union all select 'e' from dual union all select 'g' from dual union all select 'i' from dual ) select a.name name1 , b.name name2 from a , b , (select * from a union select * from b) c where a.name(+)=c.name and c.name=b.name(+) order by c.name ;
WITH TEST AS
(
SELECT 'A' form_name, 0 application_id, 0 form_id FROM DUAL UNION ALL
SELECT 'B' form_name, 0 application_id, 1 form_id FROM DUAL UNION ALL
SELECT 'C' form_name, 1 application_id, 2 form_id FROM DUAL UNION ALL
SELECT 'E' form_name, 3 application_id, 4 form_id FROM DUAL UNION ALL
SELECT 'F' form_name, 3 application_id, 5 form_id FROM DUAL UNION ALL
SELECT 'G' form_name, 4 application_id, 6 form_id FROM DUAL UNION ALL
SELECT 'H' form_name, 4 application_id, 7 form_id FROM DUAL
), TEST1 AS
(
SELECT 'A' form_name, 0 application_id, 0 form_id FROM DUAL UNION ALL
SELECT 'B' form_name, 0 application_id, 1 form_id FROM DUAL UNION ALL
SELECT 'C' form_name, 1 application_id, 2 form_id FROM DUAL UNION ALL
SELECT 'D' form_name, 2 application_id, 3 form_id FROM DUAL UNION ALL
SELECT 'E' form_name, 3 application_id, 4 form_id FROM DUAL UNION ALL
SELECT 'G' form_name, 4 application_id, 6 form_id FROM DUAL UNION ALL
SELECT 'I' form_name, 4 application_id, 8 form_id FROM DUAL
)
SELECT C.FORM_NAME
, DECODE(SUM(C.FORM_GUBUN1),1,C.FORM_NAME,NULL)
, DECODE(SUM(C.FORM_GUBUN2),1,C.FORM_NAME,NULL)
FROM (
SELECT A.FORM_NAME FORM_NAME
, 1 FORM_GUBUN1
, 0 FORM_GUBUN2
FROM TEST A
UNION ALL
SELECT B.FORM_NAME FORM_NAME
, 0 FORM_GUBUN1
, 1 FORM_GUBUN2
FROM TEST1 B) C
GROUP BY C.FORM_NAME
ORDER BY C.FORM_NAME
;
저는 이런식으로 해결했습니다~