From: Tom Lane <tgl@sss.pgh.pa.us>
To: PALAYRET Jacques <jacques.palayret@meteo.fr>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: How do work tercile, percentile & funcion percentile_cont() ?
Date: Wed, 22 Apr 2020 10:36:32 -0400
Message-ID: <8138.1587566192@sss.pgh.pa.us> (raw)
In-Reply-To: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr>
References: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr>
PALAYRET Jacques <jacques.palayret@meteo.fr> writes:
> SELECT percentile_cont(1./3) WITHIN GROUP (ORDER BY c1) FROM x ;
> percentile_cont
> ------------------
> 10.6666666666667
> (1 ligne)
> So, I though it should be :
> percentile_cont(1./3) = 10.5 (the arithmetic average between 10 et 11) and not 10.6666666666667
As far as I can see from looking at the SQL spec, this is correct;
at least, it's clear that we're *not* supposed to just interpolate
halfway between the nearest rows. The result is defined to be
T0.Y + FACTOR * (T1.Y - T0.Y)
where T0.Y and T1.Y are the nearest row values and FACTOR is
NVE*(N–1) – floor(NVE*(N–1))
where NVE is the argument of percentile_cont and N is the number of rows.
(In SQL:2003, see 10.9 <aggregate function> general rule 7)h)i).)
regards, tom lane
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: tgl@sss.pgh.pa.us, jacques.palayret@meteo.fr
Subject: Re: How do work tercile, percentile & funcion percentile_cont() ?
In-Reply-To: <8138.1587566192@sss.pgh.pa.us>
References: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr> <8138.1587566192@sss.pgh.pa.us>
* 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