SELECT '01' GB, 'A' USR FROM dual UNION ALL
SELECT '01' GB, 'B' USR FROM dual UNION ALL
SELECT '02' GB, 'C' USR FROM dual UNION ALL
SELECT '03' GB, 'D' USR FROM dual UNION ALL
SELECT '02' GB, 'A' USR FROM dual
위의 예시 테이블을 아래의 표와 같이 표현하고 싶습니다.
GB | USR | USE |
01 | A | Y |
01 | B | Y |
01 | C | N |
01 | D | N |
02 | A | Y |
02 | B | N |
02 | C | Y |
02 | D | N |
03 | A | N |
03 | B | N |
03 | C | N |
03 | D | Y |
-- 1. PARTITION OUTER JOIN -- SELECT b.gb , a.usr , NVL2(b.usr, 'Y', 'N') use FROM (SELECT DISTINCT usr FROM t) a -- 코드 테이블 별도 존재한다면 그걸 이용하세요. LEFT OUTER JOIN t b PARTITION BY (b.gb) ON (a.usr = b.usr) ORDER BY gb, usr ; -- 2. MODEL -- SELECT * FROM t MODEL PARTITION BY (gb) DIMENSION BY (usr) MEASURES ('Y' use) RULES ( use[FOR usr IN (SELECT DISTINCT usr FROM t)] = NVL(use[CV()], 'N') ) ORDER BY gb, usr ;