I'm trying to renumber a column named Count, in a SQL Server 2019 table.
The layout is like this:
date | Location | Store | Count |
---|---|---|---|
2023-02-01 | AU | Store1 | 1 |
2023-02-01 | AU | Store1 | 3 |
2023-02-01 | AU | Store1 | 4 |
2023-02-01 | UK | Store1 | 2 |
2023-02-01 | UK | Store1 | 4 |
2023-02-01 | UK | Store1 | 5 |
I am trying to renumber the Count
column, so, that for each distinct Date
, Location
and Store
, the numbers for the Count
column are contiguous, for that given Date
, Location
and Store
.
For example, for the 2023-02-01|AU|Store1
, the count should be changed from 1,3,4 to 1,2,3.
For the UK store for the same date should be changed from 2,4,5 to 1,2,3.
The count should always begin with one, for the first row for a given Date
, Location
and Store
.
I thought it would be relatively easy, but my head is hurting.
Any suggestions greatly appreciated.