여러건의 특정 컬럼 행으로 표시 하기
SELECT
col1
,col2
,SUBSTR( MAX( SYS_CONNECT_BY_PATH( merge_col, ',' )), 2 ) merge_col
FROM (
--
SELECT col1, col2, merge_col, ROW_NUMBER( ) OVER( PARTITION BY col1, col2 ORDER BY col1, col2 ) rn
FROM ( SELECT 'AAA' AS col1, 'BBB' AS col2, 'S' AS merge_col
FROM DUAL
UNION ALL
SELECT 'AAA' AS col1, 'BBB' AS col2, 'T' AS merge_col
FROM DUAL
UNION ALL
SELECT 'AAA' AS col1, 'BBB' AS col2, 'E' AS merge_col
FROM DUAL
UNION ALL
SELECT 'AAA' AS col1, 'BBB' AS col2, 'E' AS merge_col
FROM DUAL
UNION ALL
SELECT 'AAA' AS col1, 'BBB' AS col2, 'L' AS merge_col
FROM DUAL
UNION ALL
SELECT 'CCC' AS col1, 'DDD' AS col2, 'C' AS merge_col
FROM DUAL
UNION ALL
SELECT 'CCC' AS col1, 'DDD' AS col2, 'A' AS merge_col
FROM DUAL
UNION ALL
SELECT 'CCC' AS col1, 'DDD' AS col2, 'T' AS merge_col
FROM DUAL )
--
)
START WITH rn = 1
CONNECT BY PRIOR col1 = col1
AND col2 = col2
AND PRIOR rn = rn - 1
GROUP BY col1, col2
출처 : http://okhun.tistory.com/57
'DataBase > Sql' 카테고리의 다른 글
[ Oracle ] 테이블, 컬럼, 인덱스 목록 조회 (0) | 2018.11.05 |
---|---|
[Oracle] XMLAGG 를 이용한 한 행으로 표시 (0) | 2015.02.03 |
[Oracle] BLOB select (0) | 2014.01.16 |
[Sql] Oracle 까먹기쉬운 함수 정리 (0) | 2013.11.25 |
[Sql] Oracle - 계층구조 쿼리 (0) | 2013.11.25 |