Auto-increment ORACLE / PLSQL

0
Nome    Idade   ID
João    5       
Lucas   5   
João    2   
Lucas   1   

I would like to use a cursor to sort by names and by age and that the ID field would be populated according to the sequence, eg

Nome    Idade   ID
João    2       1
João    5       2
Lucas   1       1
Lucas   5       2

Is it possible?

    
asked by anonymous 28.01.2018 / 21:34

1 answer

-1

The dense_rank function assigns a ranking to the selected values. In the case of the code below, for each Name, it applies a ranking according to Age, and saves this ranking in the ID field.

SELECT Nome, Idade, DENSE_RANK() OVER ( PARTITION BY Nome ORDER BY Idade) AS ID FROM $a$ 
    
13.02.2018 / 14:17