I have a table with a column of values where each value occurs a variable number of times (i.e., one value may occur 1 time, and another value may occur 3 times). I need to add a column that identifies the occurrence sequence # of its corresponding value.
Input Table
SOURCE_VAL |
---|
a |
a |
b |
c |
c |
c |
Output table
SEQUENCE_VAL | SOURCE_VAL |
---|---|
1 | a |
2 | a |
1 | b |
1 | c |
2 | c |
3 | c |
What would the SQL for this be?