I have a column in a database which provides datetime stamps for series of sensor readings. I'd like to segment those reading into unbroken, continuous sets of sensor readings. If a sensor reading is broken, then there will be a discontinuity in the date time column. And so I'd like to perform a query on the datetime column and then compute the difference between consecutive readings.
Supposing my query is:
select sensor_time from sensor_table limit 10;
I'd get:
+---------------------+
| sensor_time |
+---------------------+
| 2009-09-28 07:08:12 |
| 2009-09-28 07:08:40 |
| 2009-09-28 07:09:10 |
| 2009-09-28 07:09:40 |
| 2009-09-28 07:10:10 |
| 2009-09-28 07:10:40 |
| 2009-09-28 07:41:10 |
| 2009-09-28 07:41:40 |
| 2009-09-28 07:42:10 |
| 2009-09-28 07:42:40 |
+---------------------+
The times in this example suddenly jump from 07:10 to 07:41, which I'd like to detect. My question is how I could compute the 9 time differences for these 10 datetime stamps? Is there some way to apply timediff() to an entire query?