I have the following dataset in SQL Server:
Name Pattern
------- -------
Peter DRF
Peter DRF
Peter BBB
Peter DRF
Peter CCC
Peter CCC
Sue DRF
Sue CCC
Sue DRF
Sue VVV
Sue SSS
I need to count the number of times a pattern changes per Name
(not only distinct changes). So my end result will be:
Peter 3
Sue 4
In other words, only counting the distinct changes. Peter changed from DRF to BBB to CCC and Sue changed from DRF to CCC to DRF to VVV to SSS.
Is this possible without using a cursor?
I have a start date and end date per row, but no unique id. Patterns gets logged by the system per person per day and sometimes multiple times per day per person.
Best Answer
First you need
row_number
/serial number.if output is ok across all data then it will perform ok.