Question

Is there any oracle statement for my problem.

Eg. TableA has 2 columns : columnA and columnB

ColumnA    ColumnB
-------------------
 A         WA
 A         WA
 B         WA
 B         WA
 C         WA
 A         CA
 A         CA
 B         CA
 B         CA
 C         CA

What I want is : AutoNumber Group by ColumnA

Auto  ColumnA  ColumnB
-----------------------
1     A        WA
2     A        WA
3     A        CA
4     A        CA
1     B        WA
2     B        WA
3     B        CA
4     B        CA
1     C        WA
2     C        CA
Was it helpful?

Solution

You can use ROW_NUMBER function for this. Group by your columnA and specify some order by clause.

SELECT ROW_NUMBER () OVER (PARTITION BY columnA ORDER BY columnB) as "auto",
       columnA, columnB
  FROM table;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top