I Have a table Like This
ID VehicleID Time EngineStatus
-- ---------- ------------------ ----------------
0 0001 1/11/2016 00:00 off
0 0002 1/11/2016 00:10 off
0 0003 1/11/2016 00:10 off
0 0001 1/11/2016 00:10 ON
0 0001 1/11/2016 00:11 ON
0 0003 1/11/2016 00:20 off
0 0002 1/11/2016 00:15 off
0 0001 1/11/2016 00:11 off
0 0001 1/11/2016 00:12 off
0 0001 1/11/2016 00:20 ON
0 0001 1/11/2016 00:25 ON
I want to get EngineStatus of every vehicle and it duration. I need a query that results like this
Start End Status VehileID
--------------- -------------- -------- ----------
1/11/2016 00:00 1/11/2016 00:10 OFF 0001
1/11/2016 00:10 1/11/2016 00:11 ON 0001
1/11/2016 00:11 1/11/2016 00:12 Off 0001
1/11/2016 00:20 1/11/2016 00:25 ON 0001
1/11/2016 00:10 1/11/2016 00:15 OFF 0002
1/11/2016 00:10 1/11/2016 00:20 OFF 0003
I think somehow I have to group the data based on continues values of a column and then get first and last row from each group.