包含 "depth from" 和 "depth to" 列的图层数据 table。使用 SQL 根据 "depth to" 条目将数据添加到 "depth from"

Layer data table with "depth from" and "depth to" columns. Using SQL to add data to "depth from" based on "depth to" entries

我得到了一个带有图层数据的 table。例如,我有 3 个对象,每个对象都有几层(土壤)。

我想以某种方式使用与 table 本身的连接,以填充空的“深度来自”单元格。我的想法是基于行数的移位连接。对于像我这样的菜鸟,有什么想法可以通过 SQL 实现这一点吗?

我的 Table 看起来像这样:

OBJID LAYID DEPTHFROM DEPTHTTO
1 0 NULL 0,3
1 1 NULL 1,4
1 2 NULL 2,8
1 3 NULL 3,6
2 0 NULL 0,6
2 1 NULL 0,9
2 2 NULL 1,1
2 3 NULL 2,2
3 0 NULL 0,5
3 1 NULL 2,4
3 2 NULL 3,9

通常对象的第一层从 0 开始。

期望的结果是:

OBJID LAYID DEPTHFROM DEPTHTTO
1 0 0 0,3
1 1 0,3 1,4
1 2 1,4 2,8
1 3 2,8 3,6
2 0 0 0,6
2 1 0,6 0,9
2 2 0,9 1,1
2 3 1,1 2,2
3 0 0 0,5
3 1 0,5 2,4
3 2 2,4 3,9

我会很高兴有一些好的想法。

table 位于 oracle 数据库上。

提前感谢您的帮助。

尝试:

select OBJID, LAYID,
       nvl (lag(DEPTHTTO) over (partition by OBJID order by LAYID), 0) as DEPTHFROM,
       DEPTHTTO
from mytable;