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.