Teradata 递归更新
Teradata update recursively
我有这样的数据记录,我想从以前的填充记录更新空白记录
enter image description here
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 激活上述结果
谢谢
我认为 Aster 不支持 lag()
上的 ignore null
s 选项。因此,您可以分两步完成此操作。使用累积和定义 "islands"。然后把值散布到周围:
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
我有这样的数据记录,我想从以前的填充记录更新空白记录 enter image description here
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 激活上述结果
谢谢
我认为 Aster 不支持 lag()
上的 ignore null
s 选项。因此,您可以分两步完成此操作。使用累积和定义 "islands"。然后把值散布到周围:
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