如何使用mysql获取所有行的列中的时间总和(How to get the sum of time in a column of all rows using mysql)

编程入门 行业动态 更新时间:2024-10-21 14:34:09
如何使用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');

更多推荐

本文发布于:2023-07-23 00:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225181.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总和   如何使用   时间   mysql   rows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!