このクエリを最適化して、それほど時間をかけずに同じ結果を得るにはどうすればよいですか? 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'
)