I have a table with column Value and Timestamp. The values keep coming in per second. So I would have data as follows
This only apply to SQL Server 2012 or later
WITH cte AS ( SELECT V,T, LAG(V) OVER (ORDER BY T) AS LAST_V FROM TABLE ) SELECT V, T FROM cte WHERE V <> LAST_V OR LAST_V IS NULL;
The LAST_V is the value of V in the previous row, ordered by T. So if V <> LAST_V it means V is not the same as LAST_V which is what was asked. The case LAST_V IS NULL means you are at the first row.