如何优化此查询以获得相同的结果,而无需花费很长时间?NOT IN
子查询需要很长时间。
SELECT DISTINCT EmployeeId FROM employees
WHERE
status = 'Active'
&& BranchId = '2'
&& NOT EXISTS (
SELECT * FROM attendance
WHERE
employees.EmployeeId = attendance.EmployeeId
&& attendance.AttendanceDate = '2015-01-20'
)
)
SELECT EmployeeId FROM employees
WHERE
status = 'Active'
&& BranchId = '2'
&& NOT IN (
SELECT EmployeeId FROM attendance WHERE AttendanceDate='2015-01-20'
)