Quito96
Quito96

Reputation: 71

calculate timediff in sec between two rows

MariaDB 10.3.36

i need to calculate the timediff in sec between the date row and
create a new column like diff_sec

enter image description here

Upvotes: 0

Views: 66

Answers (2)

Ozan Sen
Ozan Sen

Reputation: 2615

Try this code:

(MySQL Code):

SELECT id,date,section,
TIMESTAMPDIFF(SECOND,date,
LAG(date, 1) OVER (ORDER BY date)) as diff_sec 
FROM difference;

If we run the code,

Updated Solution

Upvotes: 0

Quito96
Quito96

Reputation: 71

SELECT id,date,section, TIMESTAMPDIFF(SECOND,date,
                  lag(date, 1) OVER (ORDER BY date)) as diff_sec 
FROM garagedoor;

This works for me. Thx

Upvotes: 2

Related Questions