rendered paste bodymysql> SELECT TIMESTAMPDIFF(SECOND,t1.time,t2.time) AS difference FROM example A S t1, example AS t2 WHERE t1.id+1 = t2.id;
+------------+
| difference |
+------------+
| 6 |
| 1155 |
| 13 |
| 11 |
+------------+
4 rows in set (0.00 sec)
mysql> SELECT * FROM example;
+----+---------------------+-------+
| id | time | value |
+----+---------------------+-------+
| 1 | 2006-11-14 15:31:47 | 5 |
| 2 | 2006-11-14 15:31:53 | 9 |
| 3 | 2006-11-14 15:51:08 | 9 |
| 4 | 2006-11-14 15:51:21 | 9 |
| 5 | 2006-11-14 15:51:32 | 9 |
+----+---------------------+-------+
5 rows in set (0.00 sec)