我的表格包含以下订单信息:
正如我们从该表中看到的,每个order_no都有几个重复。所以我想要的是每个order_no只保留一行(无论它是哪一个)
有谁知道怎么做? (仅供参考,我使用的是Oracle 10)
答案 0 :(得分:1)
这应该可行,即使在您的古老和过时的Oracle版本中:
delete from order_table
where rowid not in (select min(rowid)
from order_table
group by order_no);
答案 1 :(得分:1)
如果你不关心每个order_no得到哪一行,也许最简单的解决方案(在Oracle 12之前)是:
select [whatever columns you want, probably not rn - see below]
from ( select order_table.*,
row_number() over (partition by order_no order by null) as rn
)
where rn = 1
;
答案 2 :(得分:0)
以下是通过不同字段删除具有精确顺序的半重复项的查询:
main
积分转到@a_horse_with_no_name和Oracle equivalent of Postgres' DISTINCT ON?