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...