Home > database >  Oracle please answer how to remove duplicate
Oracle please answer how to remove duplicate

Time:10-06

Field 1 2
1
21 3
2 1
2 2
Into -
"Field 1 2
1
23
2 1
2

CodePudding user response:

 with a as (
Select col1, col2 2 from dual union all
Select 1, 3 from dual union all
Select 1, 4 from dual union all
Select 2, 1 from dual union all
Select 2, 2 from dual)
The select nullif (col1, lag (col1) over (partition by col1 order by rownum)) col1, col2
From a;

CodePudding user response:

CodePudding user response:

Change the way

With a as (
Select col1, col2 2 from dual union all
Select 1, 3 from dual union all
Select 1, 4 from dual union all
Select 2, 1 from dual union all
Select 2, 2 from dual)
Select the decode (row_number () over (partition by col1 order by col2), 1, col1) col1, col2
From a;
  • Related