I am looking for the best approach to this issue and have not had any luck so far. I am using Microsoft SQL Server 2008.
So here is sample data of a user:
======================
Name Status Date
======================
BOB Active 2011-03-07
BOB Active 2011-03-11
BOB Disabled 2011-03-15
BOB Disabled 2011-03-21
BOB Active 2011-03-23
BOB Active 2011-03-28
======================
I want to have this grouped so that it will show when the user actually changed the status and not the next time they were checked if the result stayed the same so what the query returns would be as follows:
======================
BOB Active 2011-03-07
BOB Disabled 2011-03-15
BOB Active 2011-03-23
======================
This is data that I do not have any access how it is created.
Any ideas on the best approach for getting this data the way I need? Keep in mind this is for Thousands of records and performance should be taken into consideration if possible. I can't think of a way to do the grouping so that it will not group the "Activate"s together and use the MIN aggregate function.
Is there a way to maybe loop through and make the data look like this for grouping and group on the last column? Would this even be the best approach?
======================
Name Status Date Group
======================
BOB Active 2011-03-07 1
BOB Active 2011-03-11 1
BOB Disabled 2011-03-15 2
BOB Disabled 2011-03-21 2
BOB Active 2011-03-23 3
BOB Active 2011-03-28 3
======================
All of my searches have not worked out, if someone could give me a key word to search for to get me on the right path that would be very much appreciated.