I have this table:
CREATE TABLE datos (
id_estacion smallint(6) DEFAULT NULL,
id_sensor smallint(6) DEFAULT NULL,
tipo_sensor smallint(6) DEFAULT NULL,
valor float DEFAULT NULL,
fecha date DEFAULT NULL,
hora time DEFAULT NULL,
id int(11) NOT NULL AUTO_INCREMENT,
dato float DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=8556 DEFAULT CHARSET=latin1;
And this data:
id_estacion fecha hora valor
1 2019-03-15 00:00:00 1164.63
1 2019-03-15 00:15:00 1164.63
1 2019-03-15 00:30:00 1164.64
1 2019-03-15 00:45:00 1164.62
1 2019-03-15 01:00:00 1164.67
1 2019-03-15 01:15:00 1164.63
1 2019-03-15 01:30:00 1164.64
I need to calculate with mysql the difference between a data and the previous data. For example the value at '00:30'
is 1164.64
, the previus value, at '00:15'
, is 1164.63
the difference is 0.01
.
id_estacion fecha hora valor diferencia
1 3/15/2019 0:00:00 1164.63 0
1 3/15/2019 0:15:00 1164.63 0
1 3/15/2019 0:30:00 1164.64 0.01
1 3/15/2019 0:45:00 1164.62 -0.02
1 3/15/2019 1:00:00 1164.67 0.05
1 3/15/2019 1:15:00 1164.63 -0.04
1 3/15/2019 1:30:00 1164.64 0.01
Is that possible? Hope you understand me.
Best regards