I have table named vehicledata which consists 4 columns: id, Veh No,Veh Mode,Timestamp.
My data looks like this:
id Veh No Veh Mode Timestamp
1 KA03-003 IDLE 16-05-2020 09:01
2 KA03-003 IDLE 16-05-2020 09:06
3 KA03-003 IDLE 16-05-2020 09:10
4 KA03-003 DRIVE 16-05-2020 09:18
5 KA03-003 DRIVE 16-05-2020 09:40
6 KA03-003 DRIVE 16-05-2020 09:41
7 KA03-003 DRIVE 16-05-2020 09:42
8 KA03-003 DRIVE 16-05-2020 09:43
9 KA03-003 IDLE 16-05-2020 09:57
10 KA03-003 IDLE 16-05-2020 10:00
11 KA03-003 IDLE 16-05-2020 10:01
12 KA03-003 DRIVE 16-05-2020 10:05
13 KA03-003 DRIVE 16-05-2020 10:07
14 KA03-003 DRIVE 16-05-2020 10:08
15 KA03-003 DRIVE 16-05-2020 10:09
16 KA05-005 IDLE 16-05-2020 09:01
17 KA05-005 IDLE 16-05-2020 09:06
18 KA05-005 IDLE 16-05-2020 09:10
19 KA05-005 DRIVE 16-05-2020 09:18
20 KA05-005 DRIVE 16-05-2020 09:40
21 KA05-005 DRIVE 16-05-2020 09:41
22 KA05-005 DRIVE 16-05-2020 09:42
23 KA05-005 DRIVE 16-05-2020 09:43
24 KA05-005 IDLE 16-05-2020 09:57
25 KA05-005 IDLE 16-05-2020 10:00
26 KA05-005 IDLE 16-05-2020 10:01
27 KA05-005 DRIVE 16-05-2020 10:05
28 KA05-005 DRIVE 16-05-2020 10:07
29 KA05-005 DRIVE 16-05-2020 10:08
30 KA05-005 DRIVE 16-05-2020 10:09
In the above table there are 2 Veh No i.e KA03-003 & KA05-005. From id 4 to 8 & 12 to 15 there are two DRIVE cycles for KAO3-003. Now refer to timestamp column where from id 4 to 8 total time of DRIVE mode is 00:25 & from id 12 to 15 total time of DRIVE mode is 00:03.Now the total time of 2 drive cycles sums up to 00:28
Similarly In Veh No KA05-005 From id 19 to 23 & 27 to 30 there are two DRIVE cycles
For these Vehicles i need to get count of 'DRIVE' cycles occured in a table & sum of time in hours format.In which result should look as below:
Veh No No.of.Drive Cycles Total Duration
KA03-003 2 00:28
KA05-005 2 00:28