In this example, the window frame can include all rows in the partition. The query calculates max(sales) sale over the entire partition (no duplicate rows in a month).
SELECT prod_id, month_num, sales, SUM(sales) OVER (PARTITION BY prod_id ORDER BY month_num ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM sale WHERE rep_id = 1 ORDER BY prod_id, month_num;
The results from the above query:
prod_id month_num sales max(sales) ------- --------- ----- ---------- 10 1 100 680 10 2 120 680 10 3 100 680 10 4 130 680 10 5 120 680 10 6 110 680 20 1 20 156 20 2 30 156 20 3 25 156 20 4 30 156 20 5 31 156 20 6 20 156 30 1 10 34 30 2 11 34 30 3 12 34 30 4 1 34
The query in this example is equivalent to:
SELECT prod_id, month_num, sales, SUM(sales) OVER (PARTITION BY prod_id ) FROM sale WHERE rep_id = 1 ORDER BY prod_id, month_num;