pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Durumdara <durumdara@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Searching for big differences between values
Date: Thu, 30 Nov 2017 17:30:03 +0100
Message-ID: <1512059403.2328.14.camel@cybertec.at> (raw)
In-Reply-To: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com>
References: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com>

Durumdara wrote:
> Somewhere the users made mistakes on prices (stock).
> 
> I need to search for big differences between values.
> For example:
> 
> 20
> 21
> 21,5
> 30
> 28
> ..
> 46392 <-
> 46392 <-
> 
> But it could be:
> 
> 42300
> 43100
> 44000
> 43800
> 65000 <-
> 42100
> 
> Human eye could locate these values, but there we need to check 30.000 articles and 450.000 values.
> 
> Do you have any idea, how to this with SQL?

You could use some variant of

  SELECT id, price
  FROM (SELECT id, price,
               avg(price) OVER (ORDER BY id ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) AS av
        FROM stock) q
  WHERE NOT (price BETWEEN 0.8 * av AND 1.25 * av);

Yours,
Laurenz Albe




view thread (5+ messages)

Message-ID: <1512059403.2328.14.camel@cybertec.at>
Permalink:  ../1512059403.2328.14.camel@cybertec.at/
Also on:    postgresql.org/message-id/1512059403.2328.14.camel@cybertec.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: laurenz.albe@cybertec.at, durumdara@gmail.com
  Subject: Re: Searching for big differences between values
  In-Reply-To: <1512059403.2328.14.camel@cybertec.at>
  References: <CAEcMXh=NgM+M+VMHbh072BEN7yqMK5j8Ndr3f8jg9MXf+rSa-Q@mail.gmail.com> <1512059403.2328.14.camel@cybertec.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