我坚持使用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