I have a database that has the following structure
+---------------------+------------+---------------+
| timestamp | EngOilP_sd | CompOilLVL_sd |
+---------------------+------------+---------------+
| 2015-06-24 20:28:07 | 0 | 0 |
| 2015-06-24 20:30:20 | 1 | 0 |
| 2015-06-24 20:36:47 | 1 | 0 |
| 2015-06-24 20:41:11 | 1 | 0 |
| 2015-06-24 20:43:29 | 1 | 0 |
| 2015-06-24 20:45:42 | 0 | 0 |
| 2015-06-24 20:47:51 | 0 | 0 |
| 2015-06-24 20:49:59 | 0 | 1 |
| 2015-06-24 20:52:01 | 0 | 1 |
| 2015-06-24 20:54:17 | 0 | 0 |
+---------------------+------------+---------------+
I would like to generate a report like the following:
sd duration start stop
EngOilP_sd 15min 22s 2015-06-24 20:30:20 2015-06-24 20:45:42
CompOilLVL_sd 4min 18s 2015-06-24 20:49:59 2015-06-24 20:54:17
I should add that it is not critical that the stop record is the first one where the value = 0, it could be the last record where the value = 1
How might I easily create a well performing query that would give me the information I need? I am using Python for the app, so I would not need the SQL to output the report in this exact form, just get me close with the guts of the information.