I have a table like this: 

```
Value TimeStamp
1   2016-04-01 00:01:09.000
0   2016-04-01 00:01:09.000
0   2016-04-01 00:01:37.000
1   2016-04-01 00:01:37.000
1   2016-04-01 00:04:52.000
1   2016-04-01 00:09:58.000
1   2016-04-01 00:15:05.000
1   2016-04-01 00:20:11.000
1   2016-04-01 00:24:49.000
1   2016-04-01 00:29:55.000
1   2016-04-01 00:31:19.000
0   2016-04-01 00:31:19.000
0   2016-04-01 00:31:46.000
1   2016-04-01 00:31:46.000
1   2016-04-01 00:35:01.000
1   2016-04-01 00:40:07.000
1   2016-04-01 00:44:46.000
1   2016-04-01 00:49:52.000
1   2016-04-01 00:54:58.000
1   2016-04-01 01:00:04.000
1   2016-04-01 01:01:28.000
0   2016-04-01 01:01:28.000
0   2016-04-01 01:05:10.000
0   2016-04-01 01:09:49.000

```

And i want to count the seconds where value is 1 (switch ON) PER DAY, here is the deal; When the timeStamp repeats it means that there was a change from 0 to 1 or viceversa in the switch value, I already had many aproches like:

```
Q1 AS (SELECT ROW_NUMBER() OVER (ORDER BY TimeStamp) AS id,
Value, Timestamp
FROM Q2
GROUP BY idVBox, sensorType, sensorSubtype, timeStamp
HAVING COUNT(TimeStamp) > 1)

Then:

SELECT A.Value, DATEDIFF(SECOND,A.TimeStamp,B.TimeStamp)
FROM Q1 AS A
INNER JOIN Q1 AS B
ON B.ID = A.ID + 1
AND B.ID%2 = 0

```

Then Group by and Sum, but here the problem is that i don't know if the value comes in 1 or 0 from the past day, and the switch can change it's state quick and never get an actual value of it's actual state. Any other idea?