From the course: Advanced SQL – Window Functions
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Framing rows and ranges - SQL Tutorial
From the course: Advanced SQL – Window Functions
Framing rows and ranges
- [Instructor] Here's a window over a dataset that consists of six rows with a pair of integer values in each, call them the green column and the brown column. First, let's partition our window by the brown column. Partition boundaries are fixed. This means that for each row within a partition, a window function will always see all partition rows. Sometimes we need to further limit the scope of a window within each partition so that not all rows use the same window, and this is what framing is all about. To define a frame, we must introduce an order so that the terms first, last, next and previous make sense. There is no such thing as first or next without an order. So let's order our rows in both partitions by the green column, in ascending order and define frame boundaries. For example, a frame that begins at the current row and ends at the following one. For the first row, this frame covers one and two, The highlighted…
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.