Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Berechnen Sie die Gesamtzeitdauer in der letzten Zeile in mysql

Versuchen Sie etwas in dieser Richtung:

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:
Gruppieren nach, mit Rollup