Calculating time difference between two following records

Can you see what this query gives you? Just trying to get 300 to appear in your “time_dif” column. The TIMESTAMPDIFF() function is used to calculate the difference in seconds between two timestamps.

SELECT
  $__timeGroupAlias(time,$__interval),
  temp_act,
  TIMESTAMPDIFF(SECOND, LAG(time) OVER (ORDER BY time), time) AS "time_dif",
  temp_act - LAG(temp_act) OVER (ORDER BY time) AS "temp_change"
FROM
  (
    SELECT
      $__timeGroupAlias(time,$__interval),
      temp_act
    FROM
      e_kiln_dp5
  ) AS t
GROUP BY 1
ORDER BY
  $__timeGroup(time,$__interval);

I may have some syntax issues in the above, so if you get an error, please try to debug before posting back.

1 Like