Re: How do work tercile, percentile & funcion percentile_cont() ?

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How do work tercile, percentile & funcion percentile_cont() ?
Date: 2020-04-22 23:03:22
Message-ID: 20200422230322.GB4048@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2020-04-22 10:00:49 +0200, PALAYRET Jacques wrote:
> From a table x(c1) containing 30 lines with integer values (column c1) from 1
> to 30 :
>
> SELECT percentile_cont(1./3) WITHIN GROUP (ORDER BY c1) FROM x ;
> percentile_cont
> ------------------
> 10.6666666666667
> (1 ligne)
> SELECT percentile_cont(2./3) WITHIN GROUP (ORDER BY c1) FROM x ;
> percentile_cont
> ------------------
> 20.3333333333333
> (1 ligne)

Think of the 30 values as points in a graph: The x values run from 0 to
29, the y values are your values. The points are connected with straight
lines. Since your y values just increase by 1 you have a straight line
from (0, 1) to (29, 30)

Then percentile_cont(1./3) is the value y value 1/3 along that line and
percentile_cont(2./3) is the y value 2/3 along that line. So you need to
find the y values corresponding to 29*(1/3) = 9.667 and 29*(2/3) = 19.333.
These are obviously 10.667 and 20.333 respectively.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christian Ramseyer 2020-04-23 06:54:35 Re: Can I tell libpq to connect to the primary?
Previous Message Peter J. Holzer 2020-04-22 22:43:32 Re: how to slow down parts of Pg