1

I have a table with 2 columns, one has a gid (serial) with intended duplicate values, I need them like that, and another column with a number, I need a 3rd column ("serial" in blue in the image) that looks like that. A serial number for each different "gid" but with the series from the "count" column

enter image description here

I tried row_number () over (partition by count order by gid) but I dont' get the correct results

EDIT: As Gordon Linoff says, I tried that and i get this results, not working as expected... enter image description here

EDIT2: It works, I just needed to order the row_number, but this alters the rest columns of my table, would be any way to make row_number work in order since beggining wthout needing to order later?

EDIT3: Actually, it works perfectly, the display was wrong

1 Answer 1

1

I think you want both gid and count in the partition by:

select row_number () over (partition by gid, count order by gid)  

You might have something more meaningful for the order by clause, if you have additional columns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.