SUM(column_name) OVER([PARTITION BY partiton_column] ORDER BY order_column)
SUM(column_name): sum 함수를 적용할 칼럼
OVER: window 함수 정의 키워드
PARTITION BY: (optional)파티션 그룹
ORDER BY:누적합을 계산 정렬 기준 열. 이 순서에 따라 누적합이 계산됩니다.
| person_id | person_name | weight | turn |
|---|---|---|---|
| 5 | Alice | 250 | 1 |
| 4 | Bob | 175 | 5 |
| 3 | Alex | 350 | 2 |
| 6 | John Cena | 400 | 3 |
| 1 | Winston | 500 | 6 |
| 2 | Marie | 200 | 4 |
select *, sum(weight) over(order by turn) as '누적합'
| person_id | person_name | weight | turn | 누적합 |
|---|---|---|---|---|
| 5 | Alice | 250 | 1 | 250 |
| 3 | Alex | 350 | 2 | 600 |
| 6 | John Cena | 400 | 3 | 1000 |
| 2 | Marie | 200 | 4 | 1200 |
| 4 | Bob | 175 | 5 | 1375 |
| 1 | Winston | 500 | 6 | 1875 |