I'm using a home automation software called OpenHAB, which writes data into a table like this:
http://sqlfiddle.com/#!9/5e35e4/1
+---------------------+-------+
| time | value |
+---------------------+-------+
| 2016-10-31 22:00:00 | 11.1 |
| 2016-10-31 22:07:08 | 10.8 |
| 2016-10-31 22:20:02 | 10.8 |
| 2016-10-31 22:30:28 | 10.8 |
| 2016-10-31 22:39:29 | 10.8 |
| 2016-10-31 22:44:04 | 10.8 |
| 2016-10-31 22:49:02 | 10.5 |
| 2016-10-31 23:00:00 | 10.5 |
| 2016-10-31 23:42:02 | 10 |
| 2016-11-01 00:00:00 | 10 |
| 2016-11-01 00:30:02 | 9.5 |
| 2016-11-01 01:00:00 | 9.5 |
| 2016-11-01 01:11:02 | 9.3 |
| 2016-11-01 01:22:02 | 9.1 |
I'm now struggling with cleaning up these values, since there are many duplicates (100k+) from the time when I started to use OpenHAB and didn't set up the logging system properly.
If the value (can be of type double or varchar) didn't change in several consecutive rows, every row except for the first and the last should be deleted. Given the example above, the optimum output would look like this:
+---------------------+-------+
| time | value |
+---------------------+-------+
| 2016-10-31 22:00:00 | 11.1 |
| 2016-10-31 22:07:08 | 10.8 | <-- only here
| 2016-10-31 22:44:04 | 10.8 |
| 2016-10-31 22:49:02 | 10.5 |
| 2016-10-31 23:00:00 | 10.5 |
| 2016-10-31 23:42:02 | 10 |
| 2016-11-01 00:00:00 | 10 |
| 2016-11-01 00:30:02 | 9.5 |
| 2016-11-01 01:00:00 | 9.5 |
| 2016-11-01 01:11:02 | 9.3 |
| 2016-11-01 01:22:02 | 9.1 |