WITH T AS (SELECT 'AA' COL1 , 'DD' COL2, '1' COL3 , '' COL4 FROM DUAL UNION ALL
SELECT 'AA' COL1 , 'II' COL2, '1' COL3 , '' COL4 FROM DUAL UNION ALL
SELECT 'BB' COL1 , 'SS' COL2, '2' COL3 , '' COL4 FROM DUAL UNION ALL
SELECT 'BB' COL1 , 'TT' COL2, '2' COL3 , '' COL4 FROM DUAL UNION ALL
SELECT 'CC' COL1 , 'II' COL2, '3' COL3 , 'DD' COL4 FROM DUAL UNION ALL
SELECT 'CC' COL1 , 'NN' COL2, '3' COL3 , '' COL4 FROM DUAL
)
SELECT * FROM T
ORDER BY COL3,COL2
AA | DD | 1 | |
AA | II | 1 | |
BB | SS | 2 | |
BB | TT | 2 | |
CC | II | 3 | DD |
CC | NN | 3 |
위와 같은 정렬을
AA | DD | 1 | |
CC | II | 3 | DD |
AA | II | 1 | |
BB | SS | 2 | |
BB | TT | 2 | |
CC | NN | 3 |
이렇게 정렬 하고 싶습니다. 쉬울듯 하면서 잘 안풀려요....
WITH T AS (SELECT 'AA' COL1 , 'DD' COL2, '1' COL3 , '' COL4 FROM DUAL UNION ALL SELECT 'AA' COL1 , 'II' COL2, '1' COL3 , '' COL4 FROM DUAL UNION ALL SELECT 'BB' COL1 , 'SS' COL2, '2' COL3 , '' COL4 FROM DUAL UNION ALL SELECT 'BB' COL1 , 'TT' COL2, '2' COL3 , '' COL4 FROM DUAL UNION ALL SELECT 'CC' COL1 , 'II' COL2, '3' COL3 , 'DD' COL4 FROM DUAL UNION ALL SELECT 'CC' COL1 , 'NN' COL2, '3' COL3 , '' COL4 FROM DUAL ) SELECT * FROM T CONNECT BY PRIOR COL2 = COL4 START WITH COL4 IS NULL order siblings by col3,col2 ;
계층 처리하는것으로 나오긴 합니다.
댓글이 글이 왜 안올라갈까요 ㅜ,.ㅜ