WITH t AS
(SELECT 1 AS cnt FROM dual UNION ALL
SELECT 2 FROM dual UNION ALL
SELECT 3 FROM dual UNION ALL
SELECT 1 FROM dual UNION ALL
SELECT 2 FROM dual UNION ALL
SELECT 1 FROM dual UNION ALL
SELECT 2 FROM dual)
SELECT * FROM t;
데이터가 이렇게 구성되어 있습니다.
1,2,3,1,2,1,2 순서이면 맨 마지막 1,2 를 가져 오고 싶습니다.
1,2,3,1,2,[1,2] 대괗호 쳐진 저부분을요.. 무슨 방법 없을까요 ㅠㅠ
WITH t AS (SELECT 1 AS cnt FROM dual UNION ALL SELECT 2 FROM dual UNION ALL SELECT 3 FROM dual UNION ALL SELECT 1 FROM dual UNION ALL SELECT 2 FROM dual UNION ALL SELECT 1 FROM dual UNION ALL SELECT 2 FROM dual) SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY ROWNUM DESC ) RN , T.* FROM T ) WHERE RN <= 2
겨우 했습니다. 감사합니다
WITH t AS
(SELECT 1 AS cnt FROM dual UNION ALL
SELECT 2 FROM dual UNION ALL
SELECT 3 FROM dual UNION ALL
SELECT 1 FROM dual UNION ALL
SELECT 2 FROM dual UNION ALL
SELECT 1 FROM dual UNION ALL
SELECT 2 FROM dual)
SELECT * FROM
(SELECT ROWNUM rn, cnt FROM t) tt
WHERE tt.rn >=
(SELECT MAX(ee) FROM
(SELECT ROWNUM AS ee, cnt FROM t
GROUP BY ROWNUM, cnt
HAVING cnt = 1));