Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRGUV-0004h5-7I for pgsql-general@arkaria.postgresql.org; Wed, 22 Apr 2020 14:36:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRGUT-0004r5-VV for pgsql-general@arkaria.postgresql.org; Wed, 22 Apr 2020 14:36:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRGUT-0004qy-Nc for pgsql-general@lists.postgresql.org; Wed, 22 Apr 2020 14:36:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRGUN-0000zk-4n for pgsql-general@lists.postgresql.org; Wed, 22 Apr 2020 14:36:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 03MEaWhp008139; Wed, 22 Apr 2020 10:36:32 -0400 From: Tom Lane To: PALAYRET Jacques cc: pgsql-general@lists.postgresql.org Subject: Re: =?utf-8?Q?How_do_work_tercile,_percentil?= =?utf-8?Q?e_&_funcion_percentile=5Fcont()=C2=A0=3F?= In-reply-to: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr> References: <1045753462.38287828.1587542449789.JavaMail.zimbra@meteo.fr> Comments: In-reply-to PALAYRET Jacques message dated "Wed, 22 Apr 2020 10:00:49 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <8137.1587566192.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 22 Apr 2020 10:36:32 -0400 Message-ID: <8138.1587566192@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PALAYRET Jacques 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) =3D 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=E2=80=931) =E2=80=93 floor(NVE*(N=E2=80=931)) where NVE is the argument of percentile_cont and N is the number of rows. (In SQL:2003, see 10.9 general rule 7)h)i).) regards, tom lane