Skip to content
Advertisement

Repeat column values in existing rows

Have a table with the following structure:

I would like to be able to pivot the table to move the Address, City, State and Zip values into columns. But for that to happen I guess I need the ID and Type to be populated for every record. Any guidance is appreciated.

Thank you

I added the rownumber field and thought about using LAG and LEAD but that did not work.

And then eventually

Advertisement

Answer

If I understand correctly, you can assign the id using a cumulative max and then use conditional aggregation:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement