In this section, we will discuss advanced window functions in more detail, and we will explore some techniques that may be useful for carrying out more detailed data analysis.
Let's start with another way to write the same aggregate that we have described before:
forumdb=# select distinct category, count(*) over w1
from posts
WINDOW w1 as (partition by category RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
order by category;
category | count
----------+-------
12 | 1
10 | 1
11 | 3
(3 rows)
What does RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW mean? They are the default conditions, known as the frame clause. This means that the data is partitioned, first by category, and then within the partition, the count is calculated by resetting the count every time the frame is changed.
The frame clause
In this section, we'll talk about the frame clause, which allows us to manage partitions in a different way. The frame...