Search code examples
sqloracle-databaserow-number

SQL - New ID for a partition


I want to have an ID which is the same for all entries within a partition.

Thinking of a table with columns lie this (having a table with the three columns on the left

enter image description here

How can I generate the new ID on the right? I thought about row_numer() over (Partion by)... but I could not find a good way to do it.


Solution

  • SELECT *, RANK() OVER (ORDER BY name, attr) as new_id
    FROM YourTable