私は mssql のクエリに固執しています。クエリは mssql で正常に実行されますが、mysql では非常に時間がかかります。
SELECT employee.ecode, fname, mname, lname
FROM employee
WHERE employee.cmp_dol IS NULL
AND employee.ecode IN (
SELECT leave_log.ecode
FROM leave_log
WHERE (
l_acc_code = 11
OR l_acc_code = 21
OR l_acc_code = 31
OR l_acc_code = 41
OR l_acc_code = 51
OR l_acc_code = 61
)
AND leave_log.l_date NOT IN (
SELECT leave_log.l_date
FROM leave_log
WHERE l_acc_code = 91
GROUP BY leave_log.ecode, l_date, l_acc_code
HAVING SUM(l_value)<>0
)
GROUP BY leave_log.ecode, l_date, l_acc_code
HAVING SUM(l_value) <> 0)
UNION
SELECT employee.ecode, fname, mname, lname
FROM employee
WHERE employee.cmp_dol IS NULL
AND employee.ecode IN (
SELECT leave_log.ecode
FROM leave_log
WHERE l_acc_code = 91
GROUP BY leave_log.ecode, l_date, l_acc_code
HAVING SUM(l_value)<>0
)
ORDER BY fname