Re: Searching for big differences between values

Поиск
Список
Период
Сортировка
От Rory Campbell-Lange
Тема Re: Searching for big differences between values
Дата
Msg-id 20171130113622.5vuts6vkz25dztwz@campbell-lange.net
обсуждение исходный текст
Ответ на Searching for big differences between values  (Durumdara <durumdara@gmail.com>)
Список pgsql-general
On 30/11/17, Durumdara (durumdara@gmail.com) 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.


В списке pgsql-general по дате отправления:

Предыдущее
От: Chris Mair
Дата:
Сообщение: Re: Searching for big differences between values
Следующее
От: "Mike Sofen"
Дата:
Сообщение: RE: copy error with json/jsonb types