PERCENTILE_DISC()
Overview
PERCENTILE_DISC()
is an ordered-set aggregate function used to compute discrete percentiles from a set of values.
The discrete percentile returns the first input value, which position in the ordering equals or exceeds the specified fraction, while multiple discrete percentiles return an array of results matching the shape of the fractions parameter, with each non-null element being replaced by the input value corresponding to that percentile.
Syntax
The syntax for this function is as follows:
PERCENTILE_DISC()
will return the first one encountered in the ordering.Parameters
- fraction
: decimal value between 0 and 1 representing the desired percentile (e.g. 0.25 for the 25th percentile)
Example
For the needs of this section we will use a simplified version of the film
table from the
Pagila database, that will contain only the title
, length
and rating
columns.
The query below calculates the quartile, median and the third quartile of film lengths:
By executing the code above, we will get the following output: