mysql>  SELECT val, ROW_NUMBER() OVER w AS ’row_number’, CUME_DIST() OVER w AS ’cume_dist’, PERCENT_RANK() OVER w AS ’percent_rank’ FROM numbers WINDOW w AS (ORDER BY val); +------+------------+--------------------+--------------+ | val | row_number | cume_dist | percent_rank | +------+------------+--------------------+--------------+ | 1 | 1 | 0.2222222222222222 | 0 | | 1 | 2 | 0.2222222222222222 | 0 | | 2 | 3 | 0.3333333333333333 | 0.25 | | 3 | 4 | 0.6666666666666666 | 0.375 | | 3 | 5 | 0.6666666666666666 | 0.375 | | 3 | 6 | 0.6666666666666666 | 0.375 | | 4 | 7 | 0.8888888888888888 | 0.75 | | 4 | 8 | 0.8888888888888888 | 0.75 | | 5 | 9 | 1 | 1 | +------+------------+--------------------+--------------+ Window Function Descriptions • DENSE_RANK() over_clause • FIRST_VALUE( expr )  [ null_treatment ]  over_clause Returns the rank of the current row within its partition, without gaps. Peers are considered ties and receive the same rank. This function assigns consecutive ranks to peer groups; the result is that groups of size greater than one do not produce noncontiguous rank numbers. For an example, see the  RANK() function description. This function should be used with  ORDER BY  to sort partition rows into the desired order. Without  ORDER BY , all rows are peers. over_clause  is as described in Section 12.21.2, “Window Function Concepts and Syntax” . Returns the value of  expr  from the first row of the window frame. over_clause  is as described in Section 12.21.2, “Window Function Concepts and Syntax” . null_treatment  is as described in the section introduction. The following query demonstrates  FIRST_VALUE() ,  LAST_VALUE() , and two instances of NTH_VALUE() : mysql>  SELECT time, subject, val, FIRST_VALUE(val) OVER w AS ’first’, LAST_VALUE(val) OVER w AS ’last’, NTH_VALUE(val, 2) OVER w AS ’second’, NTH_VALUE(val, 4) OVER w AS ’fourth’ FROM observations WINDOW w AS (PARTITION BY subject ORDER BY time ROWS UNBOUNDED PRECEDING); +----------+---------+------+-------+------+--------+--------+ | time | subject | val | first | last | second | fourth | +----------+---------+------+-------+------+--------+--------+ | 07:00:00 | st113 | 10 | 10 | 10 | NULL | NULL | | 07:15:00 | st113 | 9 | 10 | 9 | 9 | NULL | | 07:30:00 | st113 | 25 | 10 | 25 | 9 | NULL | | 07:45:00 | st113 | 20 | 10 | 20 | 9 | 20 | | 07:00:00 | xh458 | 0 | 0 | 0 | NULL | NULL | | 07:15:00 | xh458 | 10 | 0 | 10 | 10 | NULL | | 07:30:00 | xh458 | 5 | 0 | 5 | 10 | NULL | | 07:45:00 | xh458 | 30 | 0 | 30 | 10 | 30 | 2419