pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Mair <chris@1006.org>
To: Durumdara <durumdara@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Searching for big differences between values
Date: Thu, 30 Nov 2017 12:00:41 +0100
Message-ID: <932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com> (raw)
In-Reply-To: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com>
References: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com>

> I need to search for big differences between values.
[...]

Hi,

from an SQL point of view this is not difficult, but you need to
carefully define a criteria for the outliers.

For example, to find values that are more than a standard deviation
away from the mean, do something like this:

chris=# select * from val;
    x
-------
     20
     21
   21.5
     30
     28
  46392
  46393
     40
(8 rows)

chris=# select * from val where x > (select avg(x) + stddev(x) from val) or x < (select avg(x) - stddev(x) from val);
    x
-------
  46392
  46393
(2 rows)

Try with n*stddev(x) for n = 2, 3, 4, 5, ... to see
if you can get to your outliers...

Bye,
Chris.





view thread (5+ messages)  latest in thread

Message-ID: <932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com>
Permalink:  ../932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com/
Also on:    postgresql.org/message-id/932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com

 · 

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: chris@1006.org, durumdara@gmail.com
  Subject: Re: Searching for big differences between values
  In-Reply-To: <932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com>
  References: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com> <932d868d47b18e1793b20f3d2f42ab58@smtp.hushmail.com>

* 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