将两个记录合并为一个具有唯一ID的大数据

时间:2019-09-16 09:22:37

标签: mysql record

我有PNS员工的表NIP as primary keyJADWAL中包含idjadwal as primary的员工的时间表 表PRESTEMP的数据来自指纹机,格式为1行1次捕获。

我想将存储有来自指纹机的数据的表PRESTEMP转换为表PRESENSI的表timein的格式为timeoutNIP用一行索引的行NIP DATETIME 196611292006041002 2019-01-01 07:01:58 196611292006041002 2019-01-01 07:10:58 196611292006041002 2019-01-01 14:02:58 196611292006041002 2019-01-01 14:09:36

例如表名称:PRESTEMP

NIP                   DATE          TIMEIN   TIMEOUT
196611292006041002    2019-01-01    07:01:58  14:09:36

我要合并为一条记录的这四个记录取决于表JADWAL和表PNS,仅更早的时间和最近的时间。

成为表名:PRESENSI,取决于表PNS和表JADWAL

create temporary table impresensi (index tgl (tgl),index nip (nip), index timein (timein), index timeout (timeout), index shift (shift)) select jadwal.tgl jadwal.nip,jamkerja.timein,jamkerja.timeinpre,jamkerja.timeinpost, jamkerja.timeout, jamkerja.timeoutpre,jamkerja.timeoutpost,jamkerja.shift from (jadwal join jamkerja on((jadwal.idjamkerja = jamkerja.id))) where (tgl between dtanggal1 and dtanggal2);

create temporary table impresensi1 (index nip (comnip),index timein (timein), index timeout (timeout), index tanggal (tanggal), index shift (shift)) select sql_no_cache l.id,comnip,min(comtime) timein,'00:00:00' timeout, comdate tanggal,shift,comMesinID,comdatetime diffin,null diffout from prestemp l inner join impresensi r on l.comnip = nip and comdate = r.tgl where (comtime between timeinpre and timeinpost) and (comdate between dtanggal1 and dtanggal2) group by comnip, comdate;

create temporary table impresensi2 (index nip (comnip),index timein (timein), index timeout (timeout), index tanggal(tanggal), index shift (shift)) select sql_no_cache l.id,comnip,'00:00:00' timein,max(comtime) timeout, comdate tanggal,shift,comMesinID,null diffin, comdatetime diffout from prestemp l inner join impresensi r on l.comnip = r.nip and comdate = r.tgl where (comtime between timeoutpre and timeoutpost) and (comdate between dtanggal1 and dtanggal2) group by comnip,comdate;

update impresensi2 set tanggal = date_add(tanggal,interval -1 day) where shift = 1;

我在UBUNTU 14.04上使用了mysql 5.5

10.875 employees (on table PNS)

是的,我解决了我想要的东西,但是我花了很长时间来处理326.250 records (on table JADWAL),每个员工都有30天的工作日程,这意味着652.500 records,每个员工可能有2个工作日或从指纹机获得更多记录,至少1.356 seconds了一个月(在表PRESTEMP上),我得到了mcr.microsoft.com/dotnet/core/sdk:2.2来处理所有记录。

我的逻辑程序有问题吗?请帮助我减少处理时间。

0 个答案:

没有答案
相关问题