[도전] ^^* 0 0 2,750

by 박종정 [2008.05.27 14:49:27]


모양 관계상.. 1~9까지..ㅎㅎ

SELECT XMLAGG(XMLELEMENT(NUM,RPAD(TO_CHAR(NUM,’00’),4,’ ’))
                                 ORDER BY LINE_Y ASC).EXTRACT(’//text()’).GetStringVal() RESULT
FROM (
             SELECT NUM,
                              DECODE(RID_GRP,1,RID_LO+1,
                                                                   2,RID_LO+RID_RNK+1,
                                                                   3,N-RID_LO,
                                                                   4,N-(RID_LO+RID_RNK)
                               ) LINE_X,
                               DECODE(RID_GRP,1,RID_RNK+RID_LO,
                                                                    2,N-RID_LO,
                                                                    3,N-RID_RNK-RID_LO,
                                                                    4,RID_LO+1
                               ) LINE_Y     
             FROM (
                          SELECT /*+ORDERED USE_NL(A,B)*/
                                          N,
                                          RID,
                                          DECODE(RID_GRP,0,4,RID_GRP) RID_GRP,
                                          TRUNC((RID-1)/4) RID_LO,
                                          ROW_NUMBER() OVER(PARTITION BY RID ORDER BY RID) RID_RNK,
                                          ROWNUM NUM
                          FROM (
                                       SELECT N,
                                                        NO RID,
                                                        MOD(NO,4) RID_GRP,
                                                        ROW_NUMBER() OVER(PARTITION BY MOD(NO,2) ORDER BY NO DESC) NUM_CNT
                                       FROM (
                                                    SELECT 9 N  -- 자연수 넣으세요
                                                    FROM DUAL
                                                    ) D, COPY_T
                                      WHERE NO <= (N*2)-1
                                      ORDER BY RID
                                      ) A, COPY_T B
                          WHERE A.NUM_CNT >= B.NO
                         )
           )
GROUP BY LINE_X;

 

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