gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:20:26 24 4
gpt4 key购买 nike

我有一个表,其中包含时间类型的持续时间列。我正在使用 codeigniter 和 mysql 我希望总结一下时间。这样我就可以显示总秒数、小时数或分钟数。请帮助解决这个问题。

enter image description here

$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');

关于php - 如何使用mysql获取所有行的列中的时间总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33541651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com