SELECT
(
SELECT count(EmpCode) FROM master_emp E2
WHERE (EmpTypeID =1)
and EmpID not in
(
SELECT EmpID From tran_changePoint
where StartDate <= '2010-01-12' and EndDate >= '2010-01-12'
)
GROUP BY PointID
) as STT
FROM
SELECT count(EmpCode) as STT
FROM master_emp
WHERE EmpTypeID =1 and EmpID not in
(
SELECT EmpID
FROM tran_changePoint
WHERE StartDate <= '2010-01-12' and EndDate >= '2010-01-12'
)
GROUP BY PointID
ตัวอย่างนี้ NOT IN ทำให้ช้า
mysql> SELECT salary.rank FROM salary
-> WHERE rank NOT IN (SELECT rank FROM ranks);
เราสามารถปรับ ให้เขียนอย่างนี้ได้ครับ
mysql> SELECT salary.rank
-> FROM salary LEFT OUTER JOIN ranks ON (salary.rank = ranks.rank)
-> WHERE ranks.rank IS NULL;