I’m a beginner in SQL Server 2008 and i have difficulty to find solution for the folowing problem:
I’d like to do a SELECT which eliminate successive rows having the same “stat” and keep only the last occurrence.
To make myself better understood, I give you this example:
My table Results
idLigne | id | statut idLigne | id | stat
L1 1 A L2 1 A
L2 1 A L6 1 B
L3 1 B L7 1 A
L4 1 B ====> L8 1 B
L5 1 B
L6 1 B
L7 1 A
L8 1 B
Thank you.
If you assign row numbers to result set you might connect “current” and “previous” record on row number and row number – 1; if statut is not the same row from t2 will be nulled out. Testing this will give us rows having no predecessors.
Demo is at Sql Fiddle.