在我的数据库中有如下表格
+----+-----------+----------+
| id | fk_id | duration |
+----+-----------+----------+
| 1 | 23 | 00:00:31 |
| 2 | 23 | 00:00:36 |
| 3 | 677 | 00:00:36 |
| 4 | 678 | 00:00:36 |
+----+-----------+----------+
在上表中,持续时间列的数据类型为时间。
下面是那个表的schema
Create Table: CREATE TABLE `durationof` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_id` int(11) NOT NULL,
`duration` time NOT NULL,
PRIMARY KEY (`id`))
我只想在查询的持续时间列中添加所有时间,我该怎么做?
就像求和函数一样,有没有把所有mysql时间值相加的函数。
我尝试从 durationof 中选择 addtime(diration);
但这不起作用。
最佳答案
我完全不同意@Corbin's original answer .如 The TIME
Type 下所述:
TIME values may range from
'-838:59:59'
to'838:59:59'
. The hours part may be so large because theTIME
type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).
对所有此类区间求和:convert to seconds , take the sum然后 convert back again .
SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(duration))) FROM durationof
查看sqlfiddle .
关于mysql - 我想要像 sum() 这样的函数在 mysql 中添加数据类型时间列中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430635/