본문 바로가기
카테고리 없음

pgsql, oracle 상단 row의 누적 합계 구하는 쿼리

by Knowledge Store In Hyunsoft 2020. 9. 8.
SELECT reg_dt ,
	   cd ,
       SUM(col_name) AS col_name,
       SUM(SUM(col_name)) OVER(ORDER BY reg_dt ASC ROWS
              BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) 
FROM
	table_name
WHERE
	cd = '053280'
GROUP BY cd,reg_dt 
ORDER BY reg_dt
       reg_dt          cd    col_name sum 
=========================================
2020-08-18 08:31:54	053280 -293       -293
2020-08-18 08:38:25	053280    1       -292
2020-08-18 08:38:49	053280    5       -287
2020-08-18 09:00:18	053280 2719       2432
2020-08-18 09:00:22	053280  -20       2412
2020-08-18 09:00:54	053280 3000       5412
728x90

댓글