【问题标题】:Delete duplicate data from table 1 by comparing data on table 2通过比较表 2 的数据,删除表 1 中的重复数据
【发布时间】:2016-11-30 03:30:17
【问题描述】:

比如,我想删除包含 234 的一行并只保留另一行,依此类推。

**注意:我使用 IBM DB2 作为数据库。

【问题讨论】:

标签: sql db2 delete-row


【解决方案1】:
delete from table1 f0
where rrn(f0) in 
(
    select f3.rw from (
                    select rrn(f1) rw, 
                    rownumber() over(partition by Policy) rang 
                    from table1 f1 inner join table2 f2 on f1.policy=f2.policy
                   ) f3 
     where f3.rang=1
)

【讨论】:

    【解决方案2】:

    delete top(select count(a.Policy)-1 From Table1 x where x.policy in (Select distinct policy from table2)) From Table1

    【讨论】:

    • 请格式化您的代码并用几行描述您的答案,谢谢,要格式化为代码,请将您的代码扩展为左侧 4 个空格
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    相关资源
    最近更新 更多