如何过滤白天和黑夜的出勤率?

时间:2019-09-25 10:23:51

标签: php mysql laravel mariadb unpivot

我正在开发一个具有白天和黑夜时间表的计时系统。

这是我的桌子[tbl_datetime_records]

+---------------+---------------+--------------------+
| biometrics_id | employee_name |   date_time_logs   |
+---------------+---------------+--------------------+
| 1221          | EMPLOYEE 1    | 2014-07-11 09:00   |
| 1221          | EMPLOYEE 1    | 2014-07-11 18:00   |
| 1221          | EMPLOYEE 1    | 2014-07-12 08:54   |
| 1221          | EMPLOYEE 1    | 2014-07-12 18:01   |
| 7445          | EMPLOYEE 2    | 2014-07-11 09:00   |
| 7445          | EMPLOYEE 2    | 2014-07-11 18:00   |
| 7445          | EMPLOYEE 2    | 2014-07-12 08:54   |
| 7445          | EMPLOYEE 2    | 2014-07-12 18:01   |
| 2332          | EMPLOYEE 3    | 2014-07-11 18:00   |
| 2332          | EMPLOYEE 3    | 2014-07-12 02:00   |
| 2332          | EMPLOYEE 3    | 2014-07-12 02:01   |
| 2332          | EMPLOYEE 3    | 2014-07-12 18:00   |
| 2332          | EMPLOYEE 3    | 2014-07-13 02:03   |
| 4114          | EMPLOYEE 4    | 2014-07-11 08:43   |
| 4114          | EMPLOYEE 4    | 2014-07-11 08:44   |
| 4114          | EMPLOYEE 4    | 2014-07-11 14:02   |
| 4114          | EMPLOYEE 4    | 2014-07-12 08:56   |
| 4114          | EMPLOYEE 4    | 2014-07-12 18:04   |
| 4114          | EMPLOYEE 4    | 2014-07-13 09:00   |
+---------------+---------------+--------------------+

我将其过滤为FIRST IN和LAST OUT

条件:

  • 员工在同一天将有多个IN和OUT。因此规则将是先入后出。
  • 会有夜班时间表过滤。
  • 员工的超时和超时可以为空。
  • 他们的唯一标识是(biomterics_id)字段。

输出应为:

+---------------+---------------+------------------+------------------+
| biometrics_id | employee_name |  date_time_in    |  date_time_out   |
+---------------+---------------+------------------+------------------+
| 1221          | EMPLOYEE 1    | 2014-07-11 09:00 | 2014-07-11 18:00 |
| 1221          | EMPLOYEE 1    | 2014-07-12 08:54 | 2014-07-12 18:01 |
| 7445          | EMPLOYEE 2    | 2014-07-11 09:00 | 2014-07-11 18:00 |
| 7445          | EMPLOYEE 2    | 2014-07-12 08:54 | 2014-07-12 18:01 |
| 2332          | EMPLOYEE 3    | 2014-07-11 18:00 | 2014-07-12 02:01 | ---> NIGHT SHIFT
| 2332          | EMPLOYEE 3    | 2014-07-12 18:00 | 2014-07-13 02:03 | ---> NIGHT SHIFT
| 4114          | EMPLOYEE 4    | 2014-07-11 08:43 | 2014-07-11 14:02 | ---> HALF DAY
| 4114          | EMPLOYEE 4    | NULL             | 2014-07-12 18:04 | ---> NO TIME IN
| 4114          | EMPLOYEE 4    | 2014-07-1309:00  | NULL             | ---> NO TIME OUT
+---------------+---------------+------------------+------------------+

在这种情况下,我仍然没有任何想法。我正在使用MYSQL / PHP / LARAVEL

0 个答案:

没有答案