studMiner
studMiner

Reputation: 75

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.

Upvotes: 0

Views: 425

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48197

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

Upvotes: 1

Related Questions