•a positional parameter marker ( ? ) 

•a user-defined variable 

•a local variable in a stored routine 

This function should be used with ORDER BY  to sort partition rows into the desired order. 

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 percentile values resulting from dividing the rows into two or four groups. For reference, the query also displays row numbers using ROW_NUMBER() : 

mysql> SELECT val, ROW_NUMBER() OVER w AS ’row_number’, NTILE(2) OVER w AS ’ntile2’, NTILE(4) OVER w AS ’ntile4’ FROM numbers WINDOW w AS (ORDER BY val); +------+------------+--------+--------+ | val | row_number | ntile2 | ntile4 | +------+------------+--------+--------+ | 1 | 1 | 1 | 1 | | 1 | 2 | 1 | 1 | | 2 | 3 | 1 | 1 | | 3 | 4 | 1 | 2 | | 3 | 5 | 1 | 2 | | 3 | 6 | 2 | 3 | | 4 | 7 | 2 | 3 | | 4 | 8 | 2 | 4 | | 5 | 9 | 2 | 4 | +------+------------+--------+--------+ 

Beginning with MySQL 8.0.22, the construct NTILE(NULL)  is no longer permitted. 

• PERCENT_RANK() over_clause 

Returns the percentage of partition values less than the value in the current row, excluding the highest value. Return values range from 0 to 1 and represent the row relative rank, calculated as the result of this formula, where rank  is the row rank and rows  is the number of partition rows: 

( rank  - 1) / ( rows  - 1) 

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

For an example, see the CUME_DIST()  function description. 

