Jamal Hansen provides an overview of window functions:
So let’s dive in. What problem do window functions solve? They seem to do aggregation-type activities, can’t
GROUP BYdo this?The short answer is, not very well.
Window functions allow you to do things like calculate running totals, rankings, and moving averages, which tend to be very difficult to do otherwise because it requires a ‘window’ into a subset of the data.
Click through for the explanation, a primer on some of the types of window functions that are available, and several examples. I noticed that the code is impossible to read in light mode on the website, so either highlight it or go into dark mode, I guess.