What does PARTITION BY change in a window function?
It splits the window into separate groups, so that the function works inside each group on its own.
Without it, the function sees the whole table as one big group. With it, the rows are put into groups first, and the function is worked out for each group separately.
the window the function sees
-------------------------------------- ------------------------------
SUM(amount) OVER () every row in the table
SUM(amount) OVER (PARTITION BY customer) every row of each customer
SUM(amount) OVER (PARTITION BY customer
ORDER BY placed_on) each customer, in date order
So it is the same idea as the group by, with one difference. The group by collapses the rows into one row per group, and the window function keeps every row and adds the calculation beside it.
There are two things to know about it. The first one is that the partition and the order can be used together or on their own. A partition with no order gives you the total for the group on every row. An order with no partition gives you a running total across the whole table.
The second one is that the partition does not change the order of the rows in the answer. It only says which rows are neighbours for the purpose of the calculation.
The next two questions in this topic put it to work.