Mysql
 sql >> Base de données >  >> RDS >> Mysql

Calculer la durée totale de temps sur la dernière ligne dans mysql

Essayez quelque chose à cet effet :

mysql> select *, timediff(end, start) as diff, sec_to_time(SUM(timediff(end,start))) as sum FROM timet GROUP BY start WITH ROLLUP;

+---------------------+---------------------+-------+----------+----------+
| start               | end                 | g     | diff     | sum      |
+---------------------+---------------------+-------+----------+----------+
| 2011-11-28 23:00:51 | 2011-11-28 23:00:56 | 0.678 | 00:00:05 | 00:00:05 |
| 2011-11-28 23:00:52 | 2011-11-28 23:00:57 | f     | 00:00:05 | 00:00:05 |
| 2011-11-28 23:00:53 | 2011-11-28 23:00:58 | 0.948 | 00:00:03 | 00:00:05 |
| 2011-11-28 23:00:58 | 2011-11-28 23:01:01 | 0.153 | 00:00:03 | 00:00:03 |
| NULL                | 2011-11-28 23:01:01 | 0.153 | NULL     | 00:00:18 |
+---------------------+---------------------+-------+----------+----------+
5 rows in set (0.01 sec)

Mysql :
Regrouper par, avec cumul