我有一个查询,从另一个表中获取数据。我使用不存在的地方,以便我不会得到重复,但我有一个问题,我可以在我的问题中有重复的日期。我希望有一个条件,如果所有字段都相同。它不会获取数据。但如果它有一个不同的领域得到它。有人可以帮我这个吗?
INSERT INTO attendance(fk_user,date_created,time_in,time_out,total_hours,actual_ot,actual_ut)
SELECT user_dummy.id_user, t2.date_created,t2.time_in,t2.time_out,t2.total_hours,
CASE WHEN t2.total_hours >= TIME_FORMAT('9:00:00','%H:%i:%s')
THEN TIME_FORMAT(TIMEDIFF(t2.total_hours,'9:00:00'),'%H:%i:%s')
ELSE NULL
END as overtime,
CASE WHEN t2.total_hours <= TIME_FORMAT('9:00:00','%H:%i:%s')
THEN TIME_FORMAT(TIMEDIFF('9:00:00',t2.total_hours),'%H:%i:%s')
ELSE NULL
END as undertime
FROM (SELECT empno,date_created,time_in,time_out,
TIME_FORMAT(TIMEDIFF(time_out,time_in), '%H:%i:%s') as total_hours
FROM (SELECT empno, date_created,
MIN(CASE WHEN status = 0 THEN time_created END) time_in,
MAX(CASE WHEN status = 1 THEN time_created END) time_out
FROM biometrics
GROUP BY empno, date_created
) t1
) t2
LEFT JOIN user_dummy ON t2.empno=user_dummy.empno
WHERE NOT EXISTS (SELECT fk_user, date_created, time_in, time_out, total_hours, actual_ot, actual_ut
FROM attendance
WHERE attendance.date_created = t2.date_created)
AND user_dummy.id_user IS NOT NULL