결과값 하나의 col로 합치기 0 4 5,841

by 손님 SYS_CONNECT_BY_PATH ROW_NUMBER() WITH AS [2009.12.02 11:08:16]


 

 

CODE              VAL

----------------------------------------

A                         10

B                          5

C                         4

B                         5

C                         2

B                        8

 

결과값        CODE               VAL                   COUNT

                     A                       10                          1

                    B                         5|5 |8                    3

                    C                         4|2                        2

 

9i라서 XMLAGG 를 쓸 수가 없어요~

9i에선 어떤 방법이 있나요~~

by 호야 [2009.12.02 14:00:44]
SELECT GI,MAX(SYS_CONNECT_BY_PATH(VAL,'/')) VAL,MAX(CNT) CNT
FROM (SELECT GI,VAL,ROW_NUMBER() OVER(PARTITION BY GI ORDER BY ROWNUM) RN,COUNT(*) OVER (PARTITION BY GI) CNT
FROM 테이블명)
START WITH RN=1
CONNECT BY PRIOR RN=RN-1
GROUP BY GI

이런씩으로 하시면 될듯하네요

by 이재현 [2009.12.02 14:10:09]
쪼렙입니다.

WITH T AS (
SELECT 'A' AS CODE, '10' AS VAL FROM DUAL
UNION ALL SELECT 'B' AS CODE, '5' AS VAL FROM DUAL
UNION ALL SELECT 'C' AS CODE, '4' AS VAL FROM DUAL
UNION ALL SELECT 'B' AS CODE, '5' AS VAL FROM DUAL
UNION ALL SELECT 'C' AS CODE, '2' AS VAL FROM DUAL
UNION ALL SELECT 'B' AS CODE, '8' AS VAL FROM DUAL
-- UNION ALL SELECT 'B' AS CODE, '5' AS VAL FROM DUAL
)

SELECT CODE, SUBSTR(MAX(SYS_CONNECT_BY_PATH(VAL,'|')),2) AS VAL, MAX(RN)
FROM (
SELECT CODE
, VAL
, ROW_NUMBER() OVER(PARTITION BY CODE ORDER BY CODE) AS RN
FROM T
)
START WITH RN = 1
CONNECT BY PRIOR RN = RN -1
GROUP BY CODE
--GROUP BY CODE , VAL

by 마농 [2009.12.02 14:18:53]
WITH t AS
(
SELECT 'A' code, 10 val FROM dual
UNION ALL SELECT 'B', 5 FROM dual
UNION ALL SELECT 'C', 4 FROM dual
UNION ALL SELECT 'B', 5 FROM dual
UNION ALL SELECT 'C', 2 FROM dual
UNION ALL SELECT 'B', 8 FROM dual
)
, tt AS
(
SELECT code, val
, ROW_NUMBER() OVER(PARTITION BY code ORDER BY 1) rn
FROM t
)
SELECT code
, SUBSTR(MAX(SYS_CONNECT_BY_PATH(val,'|')),2) vals
, COUNT(*) cnt
FROM tt
START WITH rn = 1
CONNECT BY PRIOR code = code
AND PRIOR rn = rn - 1
GROUP BY code
;

by 손님 [2009.12.02 15:17:55]
3분 모두 답변 정말 감사합니다~
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입