I have a database table with address information like below.
address 1 | address 2 | city | state | location id
123 street name | bldg 1234 | Houston | TX | 12345
123 street name | bldg 1234 | Houston | TX | 67890
456 street name | bldg 7890 | New Orleans | LA | 56789
789 street name | bldg 0121 | long beach | CA | 98765
789 street name | bldg 0121 | long beach | CA | 53218
789 street name | bldg 0121 | long beach | CA | 13579
So even though locations have same address, they all have different ID. What I am trying to do is add a new column called 'group_number' which will group all location id that have same address.
This is my expected outcome.
Group Number | address 1 | address 2 | city | state | location id
1 | 123 street name | bldg 1234 | Houston | TX | 12345
1 | 123 street name | bldg 1234 | Houston | TX | 67890
2 | 456 street name | bldg 7890 | New Orleans | LA | 56789
3 | 789 street name | bldg 0121 | long beach | CA | 98765
3 | 789 street name | bldg 0121 | long beach | CA | 53218
3 | 789 street name | bldg 0121 | long beach | CA | 13579
I tried use windows functions like rank(), row_num() and dense_rank() and partition by address1||city||state
I thought that those functions may allow you to have same ranks in each partition. But all those functions assign ranking/sequential row numbers by partition.
Can you help me figure out the best function to create group numbers?
Thanks