我有一个有多个列,但只有三个对案例很重要,table.a
让我们将它们命名为.
我得到了这个查询:time_stamp
employee_number
station_id
SELECT checktime AS time_stamp, userid AS employee_number, SN AS station_id
FROM checkinout;
获取此信息:
+---------------------+-----------------+---------------+
| time_stamp | employee_number | station_id |
+---------------------+-----------------+---------------+
| 30/05/2015 8:01:07 | 5 | 6068144700170 |
| 31/05/2015 8:05:17 | 2 | 6068144700170 |
| 31/05/2015 17:03:47 | 2 | 6068144700170 |
| 31/05/2015 22:03:24 | 13 | 6068144700170 |
| 01/06/2015 02:30:34 | 13 | 6068144700170 |
| 01/06/2015 03:24:33 | 13 | 6068144700170 |
| 01/06/2015 07:14:24 | 13 | 6068144700170 |
| ... | ... | ... |
+---------------------+-----------------+---------------+
我需要的是每隔 20 小时按顺序对每个进行分类type
和排序。为什么不是每天?因为有些员工晚上开始工作,第二天早上完成。
分类应按计数进行,例如如果employee.a 有1 个时间戳,则t=0/s=I,如果employee.a 有2 个时间戳,则t=0/s=I - t=0/s= O,employee.a 有 3 个时间戳的情况,然后 t=0/s=I - t=2/s=O - t=0/s=O,employee.a 有 4 个时间戳的情况,然后 t=0/s= I - t=2/s=O - t=2/s=I - t=0/s=O...
所需输出示例:status
time_stamp
employee_number
time_stamp
+---------------------+-----------------+---------------+---------+-----------+
| time_stamp | employee_number | station_id | type_id | status_id |
+---------------------+-----------------+---------------+---------+-----------+
| 30/05/2015 8:01:07 | 5 | 6068144700170 | 0 | I |
| 31/05/2015 8:05:17 | 2 | 6068144700170 | 0 | I |
| 31/05/2015 17:03:47 | 2 | 6068144700170 | 0 | O |
| 31/05/2015 22:03:24 | 13 | 6068144700170 | 0 | I |
| 01/06/2015 02:30:34 | 13 | 6068144700170 | 2 | O |
| 01/06/2015 03:24:33 | 13 | 6068144700170 | 2 | I |
| 01/06/2015 07:14:24 | 13 | 6068144700170 | 0 | O |
| ... | ... | ... | ... | ... |
+---------------------+-----------------+---------------+---------+-----------+
这个问题对我有帮助,但并没有完全解决问题:
MySQL: Get start & end timestamp for each day
Mysql Show records where timestamp interval is lower than 4 minutes