Search Postgresql Archives

Re: Searching for big differences between values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30/11/17, Durumdara (durumdara@xxxxxxxxx) 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 <-

You could use window functions
https://www.postgresql.org/docs/current/static/functions-window.html

Eg
    costings=> create table vals (num integer);

    costings=> insert into vals values (20), (21), (30), (28), (46392);

    costings=> select num, num - lag(num, 1, num) over () as diff from vals
    order by num;
      num  | diff  
    -------+-------
        20 |     0
        21 |     1
        28 |    -2
        30 |     9
     46392 | 46364
    (5 rows)

Although you might want to use averaging or percentages to throw up
errors instead.




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux