更新时间:2023-12-04 14:06:53
如果你不在乎每个order_no你得到哪一行,也许最简单的解决方案(Oracle 12之前)是:
选择[无论你想要的列,可能不是rn - 见下文]
从(select order_table。*,
row_number()over(partition by order_no order by null)as rn
)
其中rn = 1
;
I have a table contains order information like below:
Order table:
As we can see from that table, each order_no has several duplicates. So what I want is to keep only one row for each order_no (no matter which one it is)
Is anyone knows how to do this? (FYI, I am using Oracle 10)
If you don't care which row you get for each order_no, perhaps the simplest solution (before Oracle 12) is:
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
;