Field for numbering or ranking distinct records - Oracle

Asked

Viewed 274 times

0

I have a problem which is this::

Knowing that a care 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 the ROWNUM does not work because it does not number for each different attendance.

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?

1 answer

0


To make this grouped numbering, it is possible to use the analytical function row_number, this allows grouping and sorting of specific records, example:

select ROW_NUMBER() OVER(partition by Atendimento order BY seq_exame) sequencia,
       t.*
  from SUA_TABELA t
  • Whoa, it worked, kid! That’s right. Thank you so much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.