teradata递归更新

3zwtqj6y  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(370)

我有这样的数据记录,我想更新空白记录从以前填写的记录输入图像描述在这里

ID  L_nbr   Code    Descripton
t001    5   S001    ABCDE
t001    12  S002    FGHI
t001    15          JKM
t001    17          NOPE
t001    18  S003    RST
t001    19          UVW
t001    21  S004    ASDS34E
t001    24          GTUS
t001    27          UNIF

预期数据如下

ID  L_nbr   Code    Descripton
t001    5   S001    ABCDE
t001    12  S002    FGHI
t001    15  S002    JKM
t001    17  S002    NOPE
t001    18  S003    RST
t001    19  S003    UVW
t001    21  S004    ASDS34E
t001    24  S004    GTUS
t001    27  S004    UNIF

请帮助我使用teradata获得以上结果
谢谢

xqkwcwgp

xqkwcwgp1#

我不认为阿斯特支持 ignore null s选项打开 lag() . 所以,你可以分两步来做。使用累积和定义“孤岛”。然后将值分散在:

select t.*, max(code) over (partition by t_id, grp) as imputed_code
from (select t.*,
             count(code) over (partition by t_id
                               order by l_nbr
                               rows between unbounded preceding and current row
                              ) as grp
      from t
     ) t

相关问题