我正在开发一个在线考勤卡系统,但遇到了障碍。我需要做的是在每一行中计算员工可能每天多次进出的日期和日期timeIn
。timeOut
我有一个工作查询来查找一整天的总数,但不是每一行。我已经包含了数据库表的结构以及我希望看到的一些示例。
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
| id | employeeID | date | timeIn | jobDescription | equipType | unitNumber | unitHours | timeOut |
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
| 8 | 1 | 01/15/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 9:30 PM |
| 9 | 1 | 01/15/13 | 10:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 12:00 PM |
| 10 | 1 | 01/16/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 5:30 PM |
| 11 | 1 | 01/17/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 5:30 PM |
| 12 | 1 | 01/18/13 | 8:00 AM | Backfill in Whispering Creek | Skid Loader | 297 | NULL | 5:30 PM |
| 13 | 1 | 01/19/13 | 8:00 AM | Backfill in Whispering Creek | Skid Loader | 297 | NULL | 3:30 PM |
| 1 | 1 | 01/20/13 | 6:00 | | Excavator | 01E | 7238 | 17:00 |
| 2 | 1 | 01/21/13 | 6:00 | Worked in Jefferson | Excavator | 01E | 7238 | 17:00 |
| 3 | 1 | 01/22/13 | 6:00 | Worked in Jefferson | Excavator | 02E | 7238 | 17:30 |
| 4 | 1 | 01/23/13 | 6:00 | Worked in Whispering Creek | Skid Loader | 32SL | 2338 | 18:30 |
| 5 | 1 | 01/24/13 | 8:00 | Worked in Hubbard | Scraper | 54C | 9638 | 11:30 |
| 6 | 1 | 01/25/13 | 8:00 | Worked in Jefferson | Dozer | 4D | 941 | 19:30 |
| 7 | 1 | 01/26/13 | 8:00 | Pushed Snow | Loader | 950H | 342 | 20:30 |
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
好的,所以我想看到的是,例如,日期以不同的值01/15/13
出现两次,我想得到一个值,说在 id 8 的行中有 2:30 小时,然后得到另一个值,说在 id 为 9 的行中有 2:00 小时。如果可能的话,我想用一个查询来完成这个。timeIn
timeOut
这是我获取一整天时间的查询:
SELECT `employeeID`, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(`timeOut`, `timeIn`)))) AS `totalTime` FROM `timeRecords` WHERE `date` = "01/15/13" AND `employeeID` = 1 GROUP BY `employeeID`;