Skip to main content
Incorporated comment
Source Link
Paul White
  • 96.1k
  • 30
  • 442
  • 691

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT TIMESTAMPDIFF(MICROSECOND, s1.date, s2.date) DIV 1000 FROM via1 s1 , via1 s2 WHERE s1.id = 1 AND s2.id = 2 ; 

There are a few errors in your CREATE TABLE statement:

CREATE TABLE via1 ( id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); 

You're using an old version of MySQL (5.5.44). From the docs:

11.3.6 Fractional Seconds in Time Values - MySQL 5.6 Reference Manual

Before MySQL 5.6.4, the instances are limited in which a fractional seconds part is permitted in temporal values. ...when MySQL stores a value into a column of any temporal data type, it discards any fractional part and does not store it.

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT TIMESTAMPDIFF(MICROSECOND, s1.date, s2.date) DIV 1000 FROM via1 s1 , via1 s2 WHERE s1.id = 1 AND s2.id = 2 ; 

There are a few errors in your CREATE TABLE statement:

CREATE TABLE via1 ( id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); 

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT TIMESTAMPDIFF(MICROSECOND, s1.date, s2.date) DIV 1000 FROM via1 s1 , via1 s2 WHERE s1.id = 1 AND s2.id = 2 ; 

There are a few errors in your CREATE TABLE statement:

CREATE TABLE via1 ( id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); 

You're using an old version of MySQL (5.5.44). From the docs:

11.3.6 Fractional Seconds in Time Values - MySQL 5.6 Reference Manual

Before MySQL 5.6.4, the instances are limited in which a fractional seconds part is permitted in temporal values. ...when MySQL stores a value into a column of any temporal data type, it discards any fractional part and does not store it.

return integer value for milis/fix create table statement
Source Link
sheepdog
  • 345
  • 2
  • 11

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT (UNIX_TIMESTAMPTIMESTAMPDIFF(r2.data)MICROSECOND, -s1.date, UNIX_TIMESTAMP(r1s2.data)date) *DIV 1000 FROM my_tablevia1 r1s1 , my_tablevia1 r2s2 WHERE r1s1.id = 1 AND r2s2.id = 2 ; 

There are a few errors in your CREATE TABLE statement:

CREATE TABLE via1 (  id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); 

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT (UNIX_TIMESTAMP(r2.data) - UNIX_TIMESTAMP(r1.data)) * 1000 FROM my_table r1 , my_table r2 WHERE r1.id = 1 AND r2.id = 2 ; 

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT TIMESTAMPDIFF(MICROSECOND, s1.date, s2.date) DIV 1000 FROM via1 s1 , via1 s2 WHERE s1.id = 1 AND s2.id = 2 ; 

There are a few errors in your CREATE TABLE statement:

CREATE TABLE via1 (  id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); 
grammar
Source Link
sheepdog
  • 345
  • 2
  • 11

If you are only looking for the difference between two rows, you can reference them by theretheir ids.

SELECT (UNIX_TIMESTAMP(r2.data) - UNIX_TIMESTAMP(r1.data)) * 1000 FROM my_table r1 , my_table r2 WHERE r1.id = 1 AND r2.id = 2 ; 

If you are only looking for the difference between two rows, you can reference them by there ids.

SELECT (UNIX_TIMESTAMP(r2.data) - UNIX_TIMESTAMP(r1.data)) * 1000 FROM my_table r1 , my_table r2 WHERE r1.id = 1 AND r2.id = 2 ; 

If you are only looking for the difference between two rows, you can reference them by their ids.

SELECT (UNIX_TIMESTAMP(r2.data) - UNIX_TIMESTAMP(r1.data)) * 1000 FROM my_table r1 , my_table r2 WHERE r1.id = 1 AND r2.id = 2 ; 
return value in miliseconds
Source Link
sheepdog
  • 345
  • 2
  • 11
Loading
added 8 characters in body
Source Link
sheepdog
  • 345
  • 2
  • 11
Loading
Source Link
sheepdog
  • 345
  • 2
  • 11
Loading