查找列中行的差异

问题描述

I want to create a new table where the difference of weight will be displayed as weight diff. for eg first day the difference is 0,so second day for the same id the weight should be like +.. for gain and - .. for loss

解决方法

你似乎想要lag()

select t.*,(weight -
        lag(weight,1,weight) over (partition by id order by date)
       ) as weight_diff
from t;

你的图片真的很难看,所以我只使用了描述中给出的名字。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...