From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Durumdara <durumdara(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Searching for big differences between values |
Date: | 2017-11-30 16:30:03 |
Message-ID: | 1512059403.2328.14.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Peter J. Holzer | 2017-11-30 17:40:05 | Re: large numbers of inserts out of memory strategy |
Previous Message | Ted Toth | 2017-11-30 14:43:32 | Re: large numbers of inserts out of memory strategy |