如何从重复值更新最旧的数据

时间:2017-06-02 13:00:49

标签: sql oracle

我在tmp表中加载了编号,当在主表中检查时可以看到一些有重复的。

我的问题是如何只从重复的值中更新1条记录。

EG。

public abstract class Widget {
    public string Color { get; set; }
}

public class Square : Widget { }

public class Circle : Widget { }

public class WidgetList {
    public IEnumerable<Widget> Widgets { get; set; }
}

表中的更多信息我有大约500K记录,其中有60K记录被复制,并且数字与示例中的数字不同,如何在同一时间更新

4 个答案:

答案 0 :(得分:1)

您可以使用rowid。像这样:

update t
    set col = . . .
    where rowid = (select min(rowid) from t where t.number = 10000006)

答案 1 :(得分:0)

试试吧

update t
set col = '....' --your update value here
where rowid = (select max(rowid) from tt where tt.number = t.number)

答案 2 :(得分:0)

使用分析获取每个数字值的最大值(rowid)。

    update t 
    set status_id = '0' 
    WHERE rowid in 
    (SELECT max(rowid) over (partition by Number)
     FROM t 
     where Number in ('10000006','46565466')
     ); 

答案 3 :(得分:-1)

您可以使用行号:

UPDATE dupes
SET SOMECOLUMN = .......
FROM dupes
WHERE 
Number+'-'+STATUS_ID+'-'+CONVERT(VARCHAR,ROW_NUMBER() OVER (PARTITION BY Number ORDER BY STATUS_ID)) 
IN
SELECT KEY
FROM
(
SELECT
Number+'-'+STATUS_ID+'-'+CONVERT(VARCHAR,ROW_NUMBER() OVER (PARTITION BY Number ORDER BY STATUS_ID)) AS KEY
ROW_NUMBER() OVER (PARTITION BY Number ORDER BY STATUS_ID) as seq
from dupes
)test
WHERE seq = 1