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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Create a window function with an OVER clause4m 11s
-
(Locked)
Partition rows within a window4m 7s
-
(Locked)
Streamline partition queries with a WINDOW clause2m 42s
-
(Locked)
Ordering data within a partition5m 8s
-
(Locked)
Calculate a moving average with a sliding window4m 52s
-
(Locked)
Return values at specific locations within a window7m 53s
-
(Locked)
Solution: Leverage window functions4m 41s
-
-
-
-
-
-