【问题标题】:How to DELETE(physical delete) rows from BiTemporal Table如何从 BiTemporal 表中删除(物理删除)行
【发布时间】:2017-01-26 23:37:00
【问题描述】:

我有一个双时态表,我需要在每个月保留当前活动行和一个历史记录行。

如果行在一个月内重复,我需要删除这些行。

 Policy_ID  Customer_ID  Validity

  497201    304779902  ('05/06/16', HIGH END)

  540944    304779902  ('07/25/16', '07/30/16')

  541077    304779902  ('07/10/16', '07/24/16')

  541145    304779902  ('07/01/16', '07/10/16')

  541008    304779902  ('06/20/16', '07/01/16')

从上面的行我需要保留 Policy_ID Customer_ID 有效性


  497201    304779902  ('05/06/16', HIGH END)

  540944    304779902  ('07/25/16', '07/30/16')

  541008    304779902  ('06/20/16', '07/01/16')

任何可以帮助执行此操作的特定命令。

【问题讨论】:

    标签: teradata


    【解决方案1】:

    要实际删除行,您需要非临时删除。最简单的方法是使用这样的临时表:

    create volatile table src as
     ( select Policy_ID, Customer_ID, Validity
       from tab
       qualify
         row_number() -- find the rows to delete
         over (partition by Customer_ID order by Validity desc) > 2
     ) with data 
    primary index (Customer_ID) -- should be the PI of the target table
    on commit preserve rows;
    
    nontemporal
    delete from tab
    where (Policy_ID, Customer_ID, Validity)
    in ( select * from src) 
    

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2021-12-26
      • 2014-04-06
      • 1970-01-01
      相关资源
      最近更新 更多