【问题标题】:Teradata update recursivelyTeradata 递归更新
【发布时间】:2020-09-05 13:38:28
【问题描述】:

我有这样的数据记录,我想从以前填充的记录中更新空白记录 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 实现上述结果

谢谢

【问题讨论】:

    标签: sql teradata-sql-assistant teradata-aster


    【解决方案1】:

    我认为 Aster 不支持 lag() 上的 ignore nulls 选项。因此,您可以分两步执行此操作。使用累积和定义“岛屿”。然后传播价值:

    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
    

    【讨论】:

    • 请告诉我应该在哪里给出表名。这段代码可以在 teradata 中工作吗
    • t 是您的餐桌。
    猜你喜欢
    • 2016-11-20
    • 2012-03-17
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    相关资源
    最近更新 更多