From the course: PostgreSQL: Advanced Queries

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Partition rows within a window

Partition rows within a window - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Partition rows within a window

- [Instructor] We just saw that the over clause will turn an aggregate function into a window function by operating on a set of data rows without actually grouping them together in the final result. With an empty set of parentheses, the over clause creates a window frame that includes all rows from a dataset. We can create partitions within this window frame in order to control the set of rows that the aggregate calculation will operate on. Let's first take a look at the average prices split up by product size. This query uses a basic aggregate function and grouping to display the results. The rows revealed the average price for each product size. I want to focus on a single size, the eight-ounce products. The average price for all eight-ounce products is $10.53. Keep that number in mind, and we'll come back to it in just a moment. Now with a window function, we saw that we can display the overall average price across an…

Contents