想要总结用户的每日工作时间,并且我有时间在时间列中签到和签出$sql=" SELECT User_id, date, min(time) AS checkedin, max(time) AS checkedout,( (TIME_TO_SEC(TIMEDIFF(max(time), min(time))) / 60) / 60) difference FROM profile WHERE 1 GROUP BY User_id, date"; $previousdata = DB::select($sql);我从我使用过的 sql 查询中得到这个数组,我想添加我每天得到的一个月数据的差异。不用担心日期格式,我来自尼泊尔,正在使用尼泊尔日期。Array( [0] => stdClass Object ( [User_id] => 1 [date] => 2076-02-06 [checkedin] => 12:11:40 [checkedout] => 19:11:43 [difference] => 7.00083333 ) [1] => stdClass Object ( [User_id] => 1 [date] => 2076-02-08 [checkedin] => 12:15:40 [checkedout] => 15:15:48 [difference] => 3.00222222 ))
2 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
如果你想用查询来做,然后使用 rollup
SELECT User_id, date, min(time) AS checkedin, max(time) AS checkedout,( (TIME_TO_SEC(TIMEDIFF(max(time), min(time))) / 60) / 60) difference
FROM profile WHERE 1 GROUP BY User_id, date WITH ROLLUP";
但它会在每组之后添加额外的行以显示它们的总和,并在结果集的底部添加一行以显示总和。
- 2 回答
- 0 关注
- 234 浏览
添加回答
举报
0/150
提交
取消