public
Authored by avatar PotatoGim

[SQL] take diff between two rows based on timestamp

diff_two_rows.sql 766 bytes
SELECT
  curr.scope,
  curr.name,
  next.scope,
  next.name,
  from_unixtime(curr.time) AS curr_time,
  from_unixtime(next.time) as next_time,
  IF(ISNULL(next.time), 0, next.time - curr.time) AS d_t,
  curr.fs_write AS curr_writes,
  next.fs_write AS next_writes,
  IF(ISNULL(next.fs_write), 0, (next.fs_write - curr.fs_write) / (next.time - curr.time)) AS d_bytes
FROM
  fs_stats AS curr
LEFT OUTER JOIN
  fs_stats AS next
    ON
      next.time = (
        SELECT MIN(time)
        FROM fs_stats
        WHERE scope = 'VM5SET4-1' AND name like '%preset_vol%' AND time > curr.time)
      AND next.scope = 'VM5SET4-1'
      AND next.name like '%preset_vol%'
WHERE curr.scope = 'VM5SET4-1' AND curr.name like '%preset_vol%'
ORDER BY curr.time;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment