
설명: 현재 행의 누적 분포 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, CUME_DIST() OVER (ORDER BY creditLimit) AS cume_dist_ex
FROM customers
;

설명: 동일한 값에 동일한 순위를 부여하며, 순위에 공백이 없습니다.
SELECT
customerNumber
, customerName
, creditLimit
, DENSE_RANK() OVER (ORDER BY creditLimit DESC) AS dense_rank_ex
FROM customers;

설명: 윈도우 프레임에서 첫 번째 행의 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, FIRST_VALUE(creditLimit) OVER (
PARTITION BY country ORDER BY customerNumber)
AS first_credit
FROM customers;

설명: 현재 행보다 N행 앞선 행의 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, LAG(creditLimit, 1, 0) OVER (ORDER BY customerNumber) AS prev_credit
FROM customers;

설명: 윈도우 프레임에서 마지막 행의 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, LAST_VALUE(creditLimit) OVER (PARTITION BY country ORDER BY customerNumber
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS last_credit
FROM customers;

설명: 현재 행보다 N행 뒤의 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, LEAD(creditLimit, 1, 0) OVER (ORDER BY customerNumber) AS next_credit
FROM customers;

설명: 윈도우 프레임에서 N번째 행의 값을 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, NTH_VALUE(creditLimit, 2) OVER (PARTITION BY country ORDER BY customerNumber
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS second_credit
FROM customers;

설명: 파티션을 N개의 버킷으로 나누고, 각 행에 버킷 번호를 부여합니다.
SELECT
customerNumber
, customerName
, creditLimit
, NTILE(4) OVER (ORDER BY creditLimit DESC) AS quartile
FROM customers;

설명: 현재 행의 백분위 순위를 반환합니다.
SELECT
customerNumber
, customerName
, creditLimit
, PERCENT_RANK() OVER (ORDER BY creditLimit) AS percent_rank_ex
FROM customers;

설명: 동일한 값에 동일한 순위를 부여하며, 순위에 공백이 있을 수 있습니다.
SELECT
customerNumber
, customerName
, creditLimit
, RANK() OVER (ORDER BY creditLimit DESC) AS rank_ex
FROM customers;

설명: 파티션 내에서 각 행에 고유한 순번을 부여합니다.
SELECT
customerNumber
, customerName
, creditLimit
, ROW_NUMBER() OVER (PARTITION BY country ORDER BY creditLimit DESC) AS row_num
FROM customers;
