我的桌子上有一个字段,它有时间做一个特定的动作。这些条目类似于00:01:29
00:02:12
00:00:45等..。
现在,我想得到所有这些时间的总和,以秒为单位。
我试过这个:
$time_for_correct_ans = Testlog::where('token', $exists->token)->where('correct', 1)->sum('answering_time');
但是它把00:01:29当成了129 seconds,这是错误的。有什么更好的方法吗?
我用的是Laravel和MySQL。
发布于 2015-02-26 17:12:36
您可以使用MySQLs TIME_TO_SEC。
$time_for_correct_ans = Testlog::selectRaw('SUM(TIME_TO_SEC(answering_time)) AS total')
->where('token', $exists->token)
->where('correct', 1)
->pluck('total');https://stackoverflow.com/questions/28748055
复制相似问题