這裏有4個表....如何優化此sql查詢?
- tbl_std_working_hour
- tbl_attendance
- tbl_holiday
- tbl_leave
我想找出這個查詢員工缺勤報告... 。但是,當我爲許多員工應用此功能時,需要時間......有什麼方法可以簡化此查詢?
SELECT date
FROM tbl_std_working_hour
WHERE date NOT IN (SELECT date FROM tbl_attendance WHERE emp_id = '$emp_id')
AND date NOT IN (SELECT date FROM tbl_holiday)
AND date NOT IN (SELECT date FROM tbl_leave WHERE emp_id = '$emp_id')
AND total_hour <> '00:00:00'
AND date >= '$start'
AND date <= '$end'
AND emp_id = '$emp_id'
見http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for什麼似乎對我來說是一個非常簡單的SQL查詢 – Strawberry