안녕하세요. ROW 정보를 가로로 표현하고자 합니다. (3개단위 씩)
그런데 빈공간이 남아서 빈공간을 없애고 싶은데 잘 안되어서 질문 드립니다.
WITH DD AS
(
SELECT '01' AS CD, 'A1' AS NM FROM DUAL
UNION ALL SELECT '02' AS CD, 'A2' AS NM FROM DUAL
UNION ALL SELECT '03' AS CD, 'A3' AS NM FROM DUAL
UNION ALL SELECT '04' AS CD, 'A4' AS NM FROM DUAL
UNION ALL SELECT '05' AS CD, 'A5' AS NM FROM DUAL
UNION ALL SELECT '06' AS CD, 'A6' AS NM FROM DUAL
UNION ALL SELECT '07' AS CD, 'A7' AS NM FROM DUAL
UNION ALL SELECT '08' AS CD, 'A8' AS NM FROM DUAL
UNION ALL SELECT '09' AS CD, 'A9' AS NM FROM DUAL
UNION ALL SELECT '10' AS CD, 'A10' AS NM FROM DUAL
UNION ALL SELECT '11' AS CD, 'A11' AS NM FROM DUAL
UNION ALL SELECT '12' AS CD, 'A12' AS NM FROM DUAL
UNION ALL SELECT '13' AS CD, 'A13' AS NM FROM DUAL
)
SELECT
MIN(DECODE(MOD(DD.CD, 3), 1, NM)) AS NM1
,MIN(DECODE(MOD(DD.CD, 3), 2, NM)) AS NM2
,MIN(DECODE(MOD(DD.CD, 3), 0, NM)) AS NM3
,MIN(DECODE(MOD(DD.CD, 3), 1, CD)) AS CD1
,MIN(DECODE(MOD(DD.CD, 3), 2, CD)) AS CD2
,MIN(DECODE(MOD(DD.CD, 3), 0, CD)) AS CD3
FROM DD
GROUP BY CD, NM
ORACLE 10 버전입니다. GROUP BY를 없애면 하나의 데이터만 나오고 둘다 사용하면 GROUP을 한거나 안한거나 똑같이 나오고
NM1 NM2 NM3 CD1 CD2 CD3
A2 02
A4 04
A3 03
A1 01
A5 05
A6 06
다음과 같이 표현 -->
NM1 NM2 NM3 CD1 CD2 CD3
A4 A2 A3 04 02 03
A1 A5 A6 01 05 06
미리 감사 드립니다.
|