I want to generate a new column with a sequential number based on a data column SortOrder
.
The Sortorder
is returned from a subquery, where I manually mapped floor designations of buildings.
Building | Floor | SortOrder |
---|---|---|
BuildingA | 1. floor | 3 |
BuildingA | rooftop | 11 |
BuildingA | ground | 0 |
BuildingB | Ground | 0 |
BuildingB | rooftop | 11 |
BuildingB | secondfloor | 4 |
This is my current query. Now I want a new column that looks like that
Building | Floor | SortOrder | Counter |
---|---|---|---|
BuildingA | 1. floor | 3 | 2 |
BuildingA | rooftop | 11 | 3 |
BuildingA | ground | 0 | 1 |
BuildingB | Ground | 0 | 1 |
BuildingB | rooftop | 11 | 3 |
BuildingB | secondfloor | 4 | 2 |
The query needs to group the buildings by their names, orders them by Sort order and create based on that a sequential number.
I tried messing around with ROW_NUMBER OVER
by joining a subquery with a group by, but that did not work out.