sql - How to get the difference in different rows within a categories in the below table? PSQL -
i want ****compute diff**** , return rows have diff>2
i don't have index column in table , not allowed add index in table because temporary table
i psql beginner. helps appreciate
thanks
you can use window functions: https://www.postgresql.org/docs/9.6/static/functions-window.html
create table temp1( client integer, value integer ); insert temp1 values (100,2), (100,5), (100,5), (102,2), (102,3); select client, value, lead(value) on (partition client order value) - value diff temp1 order client, value;
you can try at: http://rextester.com/gbkz11796
Comments
Post a Comment