I know there is a simple answer to this question but just can't get my head round it. I have a table with datetime and int columns.
| TimeStartTz | RowNumber | RateID |
|-------------------------|-----------|-------------|
| 2018-05-07 07:00:00.000 | 45 | 1 |
| 2018-04-09 07:00:00.000 | 43 | 1 |
| 2018-03-26 07:00:00.000 | 42 | 1 |
| 2018-03-19 07:00:00.000 | 41 | 1 | <-- want this row
| 2018-03-05 07:00:00.000 | 2 | 2 |
| 2018-02-26 07:00:00.000 | 1 | 2 |
| 2018-02-19 07:00:00.000 | 40 | 1 |
| 2018-02-12 07:00:00.000 | 39 | 1 |
| 2018-01-29 06:45:00.000 | 38 | 1 |
| 2018-01-22 06:45:00.000 | 37 | 1 |
I want to get the row of the most recent change in RateID or the first row if there is no change in the set, i.e. in the example the row with RowNumber
41. I tried partitioning by RateID but it obviously doesn't account for contiguous sections:
ROW_NUMBER() OVER (PARTITION BY pq.[RateID] ORDER BY pq.[TimeStart]) RowNumber