如何在 Oracle SQL 中更新多个重复行的单行

萨克蒂

我有这张桌子:

group_id | invoice_amt|insert_date
---------+------------+------
23        1002         10/8/2018
23        1002         10/8/2018
23        1003         11/8/2018
21        1004         12/8/2018

当我使用以下查询时,

select distinct group_id, invoice_amt, insert_date 
from table

我得到最后 3 行。但我需要所有四行。为此,我需要通过更改日期来更新顶行之一。Group_id 和 invoice_amt 不应更改。怎么做。?

卡米尔·戈西明斯基

如果您需要所有四行,只需 remove DISTINCT,因为它强制唯一记录集:

select group_id, invoice_amt, insert_date from table

如果您需要更改所有重复项的日期但只有一个值并且表本身没有唯一标识符,则可以使用内部 Oracle 伪列ROWID

update table t
set insert_date = < your date here >
where rowid < (
  select max(rowid)
  from table t2
  where t.group_id = t2.group_id
    and t.invoice_amt = t2.invoice_amt
  );

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章