누적값 계산
- 누적값을 계산하는 쿼리이다.
- 연도별로 누적 매출 합계를 구한다.
1 2 3 4 5 6 7 8 9 10 11
-- JOIN 이용 SELECT A.sales_month, A.sales, SUM(B.sales) AS sales_ytd FROM retail_sales AS A JOIN retail_sales AS B ON DATE_PART('year', A.sales_month) = DATE_PART('year', B.sales_month) AND B.sales_month <= A.sales_month AND B.kind_of_business = 'Women''s clothing stores' WHERE A.kind_of_business = 'Women''s clothing stores' GROUP BY A.sales_month, A.sales