유사한 쿼리 작성해 보신분에게 질문 드립니다.
WITH MASTER AS (SELECT 'W' id, '(주) 바른전자' name from dual union all SELECT 'T' , 'STS반도체통신(주)' from dual union all SELECT 'H' , '하나마이크론(주)' from dual union all SELECT 'Y' , '(주)디시티' from dual ) SELECT * FROM MASTER; WITH ID AS (SELECT ',W,T,H,Y' id FROM DUAL UNION ALL SELECT ',W,Y' id FROM DUAL UNION ALL SELECT ',Y' id FROM DUAL ) SELECT * FROM ID;
ID테이블 ID값이 ',' 시작합니다.
ID테이블 ID와 MASTER ID조인후 ID값에대한 NAME값을 출력하는 쿼리를 짜고 싶습니다.
ID값이 ',W,T,H,Y' 일경우 => (주) 바른전자, STS반도체통신(주), 하나마이크론(주), (주)디시티 출력
WITH MASTER AS (SELECT 'W' id, '(주) 바른전자' name from dual union all SELECT 'T' , 'STS반도체통신(주)' from dual union all SELECT 'H' , '하나마이크론(주)' from dual union all SELECT 'Y' , '(주)디시티' from dual ) , ID AS (SELECT ',W,T,H,Y' id FROM DUAL UNION ALL SELECT ',W,Y' id FROM DUAL UNION ALL SELECT ',Y' id FROM DUAL ) SELECT ID.ID , ListAgg(NAME, ',') WITHIN GROUP(ORDER BY MASTER.ID) NAME FROM ID , MASTER WHERE INSTR(ID.ID,MASTER.ID) > 0 GROUP BY ID.ID ORDER BY ID.ID ;