Window Frame
As mentioned in the earlier sections discussing the basics of window functions, by default, a window is set for each value group to encompass all the rows from the first to the current row in the partition, as shown in Figure 5.6. However, this is the default and can be adjusted using the window frame
clause. A window function query using the window frame clause would look as follows:
SELECT {columns}, {window_func} OVER ( PARTITION BY {partition_key} ORDER BY {order_key} {rangeorrows} BETWEEN {frame_start} AND {frame_end} ) FROM {table1};
Here, {columns}
are the columns to retrieve from tables for the query, {window_func}
is the window function you want to use, {partition_key}
is the column or columns you want to partition on, {order_key}
is the column or columns you want to order by, {rangeorrows}
is either the RANGE
keyword or the ROWS
keyword...