[답변] 고수는 아닙니다. 0 1 2,195

by 성시현 [2007.07.19 18:08:41]


테스트 데이터...

WITH
  t AS
    (
    SELECT 'a' AS item, 1 AS col, 'ㅁ' AS val FROM dual UNION ALL
    SELECT 'a' AS item, 3 AS col, 'ㅁ' AS val FROM dual UNION ALL
    SELECT 'a' AS item, 3 AS col, 'ㅁ' AS val FROM dual UNION ALL
    SELECT 'b' AS item, 2 AS col, 'ㅇ' AS val FROM dual UNION ALL
    SELECT 'b' AS item, 4 AS col, 'ㅇ' AS val FROM dual UNION ALL
    SELECT 'b' AS item, 4 AS col, 'ㅇ' AS val FROM dual
    )

 

쿼리...

SELECT
      item AS 항목
    , MIN(DECODE(col, 1, val)) AS "1"
    , MIN(DECODE(col, 2, val)) AS "2"
    , MIN(DECODE(col, 3, val)) AS "3"
    , MIN(DECODE(col, 4, val)) AS "4"
    , MIN(DECODE(col, 5, val)) AS "5"
    , MIN(DECODE(col, 6, val)) AS "6"
FROM(
    SELECT
          t.*
        , ROW_NUMBER() OVER(PARTITION BY item, col ORDER BY ROWNUM) AS rn
    FROM t
    )
GROUP BY item, rn
ORDER BY item, rn

 

건승하시길...수고하세요~~

by 양희종 [2007.07.19 00:00:00]
감사합니다.
ROW_NUMBER() OVER(PARTITION BY item, col ORDER BY ROWNUM)

이런 함수도있었군요 ^^;;
감사합니다.
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입