Field to number or rank different records - Oracle

0

I have a problem that is as follows:

Knowing that a service can have several exams, I need to number the exams in order to know the first, second, third ..., for each service. Example:

LINHA  ATENDIMENTO  SEQ_EXAME     
1      100          11        
2      100          13
3      100          17
1      200          83   
2      200          92   

Using ROWNUM does not work because it does not number for each different service.

LINHA  ATENDIMENTO  SEQ_EXAME     
1      100          11        
2      100          13
3      100          17
4      200          83   
5      200          92  

Could you help me by suggesting some solutions?

    
asked by anonymous 16.10.2018 / 12:55

1 answer

0

To make this grouped numbering, you can use the analytic function > row_number , this allows you to group and sort specific records, eg

select ROW_NUMBER() OVER(partition by Atendimento order BY seq_exame) sequencia,
       t.*
  from SUA_TABELA t
    
16.10.2018 / 15:42