I’m relatively new to databases and I’m now approaching a problem I couldn’t find a solution for by myself or in forums. I have a (InnoDB) Database which contains temperature readings which are related to a timestamp an a sensorID. My problem with this data is, that the temperature readings often jump from one value to the next and back and so forth (please also notice the attached picture). The entries look like this:
+------------+----------+-------------+ | timestamp | sensorID | temperature | +------------+----------+-------------+ | 1511020195 | 1 | 25 | | 1511020195 | 2 | 32 | | 1511020196 | 1 | 26 | | 1511020197 | 1 | 25 | | 1511020197 | 2 | 31 | | 1511020198 | 1 | 26 | | 1511020199 | 1 | 25 | | 1511020199 | 2 | 32 | +------------+----------+-------------+
My question is, if there is a way to find these jumping back and forth entries and to reduce them to only one temperature value (preferably the lowest). This should reduce the space needed for my database drastically. Thank you everyone in advance!
Edit: A more minimalistic example of my data:
+------------+----------+-------------+ | timestamp | sensorID | temperature | +------------+----------+-------------+ | 1511020195 | 1 | 25 | | 1511020196 | 1 | 26 | | 1511020197 | 1 | 25 | | 1511020198 | 1 | 26 | | 1511020199 | 1 | 27 | | 1511020200 | 1 | 28 | +------------+----------+-------------+
Which should look like this after modification:
+------------+----------+-------------+ | timestamp | sensorID | temperature | +------------+----------+-------------+ | 1511020195 | 1 | 25 | | 1511020198 | 1 | 26 | | 1511020199 | 1 | 27 | | 1511020200 | 1 | 28 | +------------+----------+-------------+
Edit 2: The Temperatures are jumping back an forth because of the sensors resolution of 1 degree. If the real temperature is on the edge between on value and an other value, the readings start to jump between those values before the real temperature is a bit ahead of this edge. So, what I want is to clean up my data. If the Temperature jumps between 25 and 26 degrees, there should only be two values left in my db. 25 for the first 25 reading and 26 for the last 26 reading before a 27 reading occurs in my data. The same should work in the other direction as well. If the readings jump between 25 and 26 and then a 24 reading occours, there should be one 26, one 25 and the 24 degree reading left.