从CTE中删除重复的DB2数据

时间:2013-07-02 20:12:58

标签: sql db2

我有以下DB2代码,其中列出了一些我需要删除的重复错误行。任何人都可以帮助将其变成删除声明吗?

with AN as (select AN 
            from SCHEMA1.ACCR 
            where TIME = '2013-06-01')  
select * 
from AN a 
inner join SCHEMA1.ACCR b 
        on a.AN = b.AN 
where TIME = '2012-06-01'

谢谢!

2 个答案:

答案 0 :(得分:1)

这是我最终使用的:

DELETE
from SCHEMA1.ACCR b 
WHERE AN IN  (select AN from SCHEMA1.ACCR where TIME='2013-06-01') 
AND TIME'2012-06-01'

感谢您提出问题/建议。

答案 1 :(得分:0)

with AN 
as (select AN 
from SCHEMA1.ACCR 
where TIME='2013-06-01')  
delete b
from AN a 
inner join SCHEMA1.ACCR b 
on a.AN=b.AN 
where TIME='2012-06-01'