stefano542
stefano542

Reputation: 91

Adding same ID to same rows

I have a problem in SQL postgres. I'm starting with this kind of table:

Starting Table

As you can see, I have some rows with same year, month, day, which can often occur. For each of them the columns count and dmg are different. I want to associate for each of these rows with same year,month,day but different count and dmg, the same number id, as you can see in the next img:

Finished Table

wish someone could help me. thanks in advance!

Upvotes: 0

Views: 39

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

You can use dense_rank():

select dense_rank() over (order by year, month, day) as id,
       t.*
from t;

Upvotes: 2

Related Questions