我有考勤表和导入表。导入表如下
ID | 约会时间 |
---|---|
1001 | 2023-08-15 8:00:00 |
1002 | 2023-08-15 8:01:00 |
1001 | 2023-08-15 19:31:00 |
1002 | 2023-08-15 19:35:00 |
**我获取这些数据并使用Min(date_time)和max(date_time)**将我的出勤表插入到出勤表、EMPID、TimeIN、TimeOUT 中,如下所示
EMPID | 时间输入 | 暂停 |
---|---|---|
1001 | 2023-08-15 8:00:00 | 2023-08-15 19:31:00 |
1002 | 2023-08-15 8:01:00 | 2023-08-15 19:35:00 |
但在中午,如果我导入数据,我的出勤表如下所示
EMPID | 时间输入 | 暂停 |
---|---|---|
1001 | 2023-08-16 8:21:00 | 2023-08-15 08:21:00 |
1001 | 2023-08-16 20:01:00 | 2023-08-15 20:01:00 |
我需要更新考勤表 TimeIN 8:21:00 和 TimeOUT 20:01:00 并删除第二行
我尝试使用下面的代码创建临时表(att_duplicate) INSERT INTO att_duplicate SELECT EMPID, min(TimeIN) as TimeIN, max(TimeOUT) as TimeOUT, SN from attendance GROUP by EMPID, date(TimeIN) HAVING COUNT(TimeIN)>1 ORDER BY EMPID, TimeIN;
然后我使用下面的代码更新出勤表与 att_duplicate 表的连接 UPDATE attendance att JOIN att_duplicate dup ON att.EMPID = dup.EMPID AND DATE(att.TimeIN)= date(dup.TimeIN) SET att.TimeOUT = dup.TimeOUT, att.TimeIN = dup.TimeIN
然后我使用下面的代码删除出勤表重复记录,但这需要很长时间… DELETE a1 FROM attendance a1 JOIN attendance a2 ON a1.EMPID = a2.EMPID AND a1.TimeIN = a2.TimeIN AND a1.SN > a2.SN;
请问这个方法是错误的吗,有没有更好更快的方法
我需要更好更快的方法