如何在MySQL中汇总VARCHAR数据类型或TIME数据类型的行?
让我们首先创建一个-
mysql> create table DemoTable1442 -> ( -> DueTime time -> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1442 values('00:08:00'); mysql> insert into DemoTable1442 values('00:04:00'); mysql> insert into DemoTable1442 values('12:55:00');
使用选择显示表中的所有记录-
mysql> select * from DemoTable1442;
这将产生以下输出-
+----------+ | DueTime | +----------+ | 00:08:00 | | 00:04:00 | | 12:55:00 | +----------+ 3 rows in set (0.00 sec)
以下是对MySQL中VARCHAR数据类型或TIME数据类型的行求和的查询-
mysql> select sec_to_time(sum(time_to_sec(DueTime) ) ) as TotalTime from DemoTable1442;
这将产生以下输出-
+-----------+ | TotalTime | +-----------+ | 13:07:00 | +-----------+ 1 row in set (0.03 sec)