PERCENTILE_CONT()
Overview
PERCENTILE_CONT()
is an ordered-set aggregate function used to compute continuous percentiles from a set of values. The continuous percentile returns an interpolated value based on the distribution of the input data, while multiple continuous percentiles return an array of results matching the shape of the fractions
parameter with each non-null element replaced by the value corresponding to that percentile.
Syntax
The syntax for this function is as follows:
WITHIN GROUP
clause to specify how to order the data before calculating the percentile.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.
This query calculates the median film length within each rating category.
By executing the code above we will get the following output: