content_image/729877.jpg
For information about optimization and window functions, see Section 8.2.1.21, “Window Function Optimization” . 

## 12.21.1 Window Function Descriptions 

This section describes nonaggregate window functions that, for each row from a query, perform a calculation using rows related to that row. Most aggregate functions also can be used as window functions; see Section 12.20.1, “Aggregate Function Descriptions” . 

For window function usage information and examples, and definitions of terms such as the OVER  clause, window, partition, frame, and peer, see Section 12.21.2, “Window Function Concepts and Syntax” . 

<img src='content_image/729877.jpg'>

In the following function descriptions, over_clause  represents the OVER  clause, described in Section 12.21.2, “Window Function Concepts and Syntax” . Some window functions permit a null_treatment  clause that specifies how to handle NULL  values when calculating results. This clause is optional. It is part of the SQL standard, but the MySQL implementation permits only RESPECT NULLS (which is also the default). This means that NULL  values are considered when calculating results. IGNORE NULLS  is parsed, but produces an error. 

• CUME_DIST() over_clause 

Returns the cumulative distribution of a value within a group of values; that is, the percentage of partition values less than or equal to the value in the current row. This represents the number of rows preceding or peer with the current row in the window ordering of the window partition divided by the total number of rows in the window partition. Return values range from 0 to 1. 

This function should be used with ORDER BY  to sort partition rows into the desired order. Without ORDER BY , all rows are peers and have value N / N  = 1, where N  is the partition size. 

over_clause  is as described in Section 12.21.2, “Window Function Concepts and Syntax” . 

The following query shows, for the set of values in the val  column, the CUME_DIST()  value for each row, as well as the percentage rank value returned by the similar PERCENT_RANK()  function. For reference, the query also displays row numbers using ROW_NUMBER() : 

