如何使用mysql获取所有行的列中的时间总和(How to get the sum of time in a column of all rows using mysql)
我有一个表,其中包含time类型的duration列。 我正在使用codeigniter和mysql我想要总结一下这个时间。 所以我可以在几秒,几小时或几分钟内显示它。请帮助解决这个问题。
$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/>"; }
I have a table which contains duration column that is of type time. I am using codeigniter and mysql i want that time to be summed up. So that i can display that in total seconds, hours or minutes.Please help to sort out this issue.
$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');Use SEC_TO_TIME to convert time into second
$this->db->select('SEC_TO_TIME( SUM( TIME_TO_SEC( `duration` ) ) ) AS timeSum '); $this->db->where('itemid',$id); $query = $this->db->get('duration');更多推荐
发布评论