要将时间转换为秒,请使用TIME_TO_SEC()方法。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> ArrivalTime time -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('04:10:00'); mysql> insert into DemoTable values('05:20:50'); mysql> insert into DemoTable values('06:40:10');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-------------+ | ArrivalTime | +-------------+ | 04:10:00 | | 05:20:50 | | 06:40:10 | +-------------+ 3 rows in set (0.00 sec)
以下是查询以计算MySQL中的时间总和-
mysql> select SEC_TO_TIME( SUM( TIME_TO_SEC( ArrivalTime) ) ) from DemoTable;
输出结果
+-------------------------------------------------+ | SEC_TO_TIME( SUM( TIME_TO_SEC( ArrivalTime) ) ) | +-------------------------------------------------+ | 16:11:00 | +-------------------------------------------------+ 1 row in set (0.00 sec)