I have multiple sensors and every value is recorded every 20S in my dB. Each recording has an ID, value, sensor id and timestamp. I would like to find an SQL request that would allow me to get the difference between the values reported by 2 sensors at near similar times. So for instance, for each value of sensor 5, I would like to get the difference with the closest value for sensor 5. Then I would like to also ensure that both values are not too far in time (20s for instance) and return a value only in that case.
Would anyone have pointers or even a syntax to do this? I know influx is made for this stuff, but I know SQL only and don't yet understand nosql design so for now it's mysql.
Thanks in advance for the help!