SELECT '20180001' AS T1,
'TEST1' AS T2
FROM DUAL
UNION ALL
SELECT '20180001' AS T1,
'TEST2' AS T2
FROM DUAL
UNION ALL
SELECT '20180002' AS T1,
'TEST3' AS T2
FROM DUAL
UNION ALL
SELECT '20180002' AS T1,
'TEST4' AS T2
FROM DUAL;
Q1. 위의 데이터에서 아래와 같이 T1컬럼 같은 숫자끼리 CNT 번호별로 보이게 쿼리할려면 어떻게 해야 할까요? T1컬럼의 정렬은 역순입니다ㅏ.. 간단한거 같으면서 어렵네요 ㅠㅠ
CNT | T1 | T2 |
1 | 20180002 | TEST3 |
1 | 20180002 | TEST4 |
2 | 20180001 | TEST1 |
2 | 20180001 | TEST2 |
WITH T AS ( SELECT '20180001' AS T1, 'TEST1' AS T2 FROM DUAL UNION ALL SELECT '20180001' AS T1, 'TEST2' AS T2 FROM DUAL UNION ALL SELECT '20180002' AS T1, 'TEST3' AS T2 FROM DUAL UNION ALL SELECT '20180002' AS T1, 'TEST4' AS T2 FROM DUAL ) SELECT B.RN CNT , A.T1 , A.T2 FROM T A , (SELECT ROWNUM RN , T1 FROM (SELECT T1 FROM T GROUP BY T1 ORDER BY T1 DESC ) ) B WHERE A.T1 = B.T1 ORDER BY A.T1 DESC