Window Function Frame Specification For the  running_average  column, there is no frame row preceding the first one or following the last. In these cases,  AVG()  computes the average of the rows that are available. Aggregate functions used as window functions operate on rows in the current row frame, as do these nonaggregate window functions: Standard SQL specifies that window functions that operate on the entire partition should have no frame clause. MySQL permits a frame clause for such functions but ignores it. These functions use the entire partition even if a frame is specified: The frame clause, if given, has this syntax: In the absence of a frame clause, the default frame depends on whether an  ORDER BY  clause is present, as described later in this section. The  frame_units  value indicates the type of relationship between the current row and frame rows: The  frame_extent  value indicates the start and end points of the frame. You can specify just the start of the frame (in which case the current row is implicitly the end) or use  BETWEEN  to specify both frame endpoints: • RANGE : The frame is defined by rows within a value range. Offsets are differences in row values from the current row value. • ROWS : The frame is defined by beginning and ending row positions. Offsets are differences in row numbers from the current row number. 2429 frame_clause : frame_units frame_extent frame_units : {ROWS | RANGE} CUME_DIST() DENSE_RANK() LAG() LEAD() NTILE() PERCENT_RANK() RANK() ROW_NUMBER() FIRST_VALUE() LAST_VALUE() NTH_VALUE() AVG(val) OVER (PARTITION BY subject ORDER BY time ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS running_average FROM observations; +----------+---------+------+---------------+-----------------+ | time | subject | val | running_total | running_average | +----------+---------+------+---------------+-----------------+ | 07:00:00 | st113 | 10 | 10 | 9.5000 | | 07:15:00 | st113 | 9 | 19 | 14.6667 | | 07:30:00 | st113 | 25 | 44 | 18.0000 | | 07:45:00 | st113 | 20 | 64 | 22.5000 | | 07:00:00 | xh458 | 0 | 0 | 5.0000 | | 07:15:00 | xh458 | 10 | 10 | 5.0000 | | 07:30:00 | xh458 | 5 | 15 | 15.0000 | | 07:45:00 | xh458 | 30 | 45 | 20.0000 | | 08:00:00 | xh458 | 25 | 70 | 27.5000 | +----------+---------+------+---------------+-----------------+