如何使用 mysql 获取所有行的列中的时间总和

How to get the sum of time in a column of all rows using mysql

我有一个 table,其中包含时间类型的持续时间列。我正在使用 codeigniter 并且 mysql 我希望总结那个时间。这样我就可以显示总秒数、小时数或 minutes.Please 有助于解决这个问题。

$condition = "itemid =" . "'" . $section_id . "'";
$this->db->select('*, SEC_TO_TIME(SUM(TIME_TO_SEC(`duration`))) AS timeSum ');
$this->db->from('duration');
$this->db->where($condition);
$query = $this->db->get();


foreach($query->result_array() as $row1)
{
$row['course_data'][] = $row1;
echo "time".$row1['timeSum']."<br/>";
}

使用SEC_TO_TIME将时间转换为秒

$this->db->select('SEC_TO_TIME( SUM( TIME_TO_SEC( `duration` ) ) ) AS timeSum '); 
$this->db->where('itemid',$id);
$query = $this->db->get('duration');