2016-09-19 76 views
0

我有一個bitemporal表,我需要在每個月保留當前活動行和一個歷史記錄行。如何從BiTemporal表中刪除(物理刪除)行

如果行在月內重複,我需要刪除這些行。

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') 

任何特定的命令,它可以幫助做到這一點。

回答

0

要實際刪除行,您需要NONTEMPORAL刪除。最簡單的方法使用這樣的臨時表:

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)