728x90
반응형
-- PREDECING AND FOLLOWING TEST
WITH UNBOUNDED_TEST AS (SELECT '1' AS COL1, '' AS COL2 FROM DUAL
UNION ALL
SELECT '2' AS COL1, '1' AS COL2 FROM DUAL
UNION ALL
SELECT '3' AS COL1, '2' AS COL2 FROM DUAL
UNION ALL
SELECT '4' AS COL1, '3' AS COL2 FROM DUAL
) SELECT
FIRST_VALUE(COL1) OVER (PARTITION BY COL1 ORDER BY CO1 ROWS UNBOUNDED PRECEDING) AS UNBOUNDED_PRECEDING
,FIRST_VALUE(COL1) OVER (ORDER BY COL1 ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS ONE_PRECEDING_AND_CURRENT_ROW
,FIRST_VALUE(COL1) OVER (ORDER BY COL1 ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS TWO_PRECEDING_AND_CURRENT_ROW
,FIRST_VALUE(COL1) OVER (ORDER BY COL1 ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS THREE_PRECEDING AND_CURRENT_ROW
,FIRST_VALUE(COL1) OVER (ORDER BY COL1 ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS CURRENT_ROW_AND_1
,FIRST_VALUE(COL1) OVER (ORDER BY COL1 ROWS BETWEEN CURRENT ROW AND 4 FOLLOWING) AS CURRENT_ROW_AND_MAX_VALUE_TEST
FROM UNBOUNDED_TEST
--END OF TEST
결과값▼
UNBOUNDED_PRECEDING | ONE_PRECEDING_AND_CURRENT_ROW | TWO_PRECEDING_AND_CURRENT_ROW | THREE_PRECEDING_AND_CURRENT_ROW | CURRENT_ROW_AND_1 | CURRENT_ROW_AND_MAX_VALUE |
1 | 1 | 1 | 1 | 1 | 1 |
2 | 1 | 1 | 1 | 2 | 2 |
3 | 2 | 1 | 1 | 3 | 3 |
4 | 3 | 2 | 1 | 4 | 4 |
728x90
'SQL > Oracle' 카테고리의 다른 글
GRETEST/LEAST VS MAX/MIN 비교 (오라클) (0) | 2021.06.16 |
---|---|
oracle_ unpivot 활용 (0) | 2021.06.11 |
NVL vs NVL2 vs COALESCE vs NULLIF 구문차이정리 (0) | 2021.03.03 |
오라클 자주사용하는 힌트목록 정리(친절한 sql 튜닝) (1) | 2021.02.04 |