pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: How do work tercile, percentile & funcion percentile_cont() ?
Date: Thu, 23 Apr 2020 01:03:22 +0200
Message-ID: <20200422230322.GB4048@hjp.at> (raw)
In-Reply-To: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr>
References: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr>

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@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (5+ messages)

Message-ID: <20200422230322.GB4048@hjp.at>
Permalink:  ../20200422230322.GB4048@hjp.at/
Also on:    postgresql.org/message-id/20200422230322.GB4048@hjp.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hjp-pgsql@hjp.at
  Subject: Re: How do work tercile, percentile & funcion percentile_cont() ?
  In-Reply-To: <20200422230322.GB4048@hjp.at>
  References: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr> <20200422230322.GB4048@hjp.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox