想要總結用戶的每日工作時間,并且我有時間在時間列中簽到和簽出$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 關注
- 270 瀏覽
添加回答
舉報
0/150
提交
取消