SELECT t.key, t.date, t.v, (COALESCE(t1.v, 0) - t.v) dv FROM table t LEFT JOIN table t1 ON t1.key = t.key + 1