^^* 0 0 2,442

by 박종정 [2008.05.20 17:18:51]


잼있을것 같아 해보았습니다..ㅎㅎ

1       2       3

8             4

7       6       5

위에 보시면,

빨강 1그룹 

파랑 2그룹

검정 3그룹

녹색 4그룹

갈색 5그룹

나눌수 있습니다. 그룹은 자연수 (n*2)-1 개 만큼 나오구요~

CONNECT BY 절 사용하지 않구 COPY_T 이용했습니다.. 귀차니즘이어욤..ㅜㅜ

COPY_T 컬럼명이 NO 일때  데이타는 1,2,3.......N 들어있다치고..^^*

====================================================

 
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
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 3-- 자연수 넣으세요
                                       FROM DUAL
                                       ) D, COPY_T
                          WHERE NO <= (N*2)-1
                          ORDER BY RID
                         ) A, COPY_T B
            WHERE A.NUM_CNT >= B.NO    
           );

 

 

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