我已将以下查询从 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 )
GROUP BY leave_log.ecode, l_date, l_acc_code
HAVING SUM(l_value) <> 0)
AND employee.ecode IN ((SELECT ecode
FROM emp_supervisor
WHERE sup_id = @ecode
AND emp_sup_dol IS NULL)
UNION
(SELECT ecode
FROM emp_project
WHERE proj_emp_dol IS NULL
AND pid IN (SELECT pid
FROM proj_supervisor
WHERE proj_sup_dol IS NULL
AND sup_id =@ecode
AND pid IN (SELECT pid
FROM projects
WHERE p_end_date IS NULL
AND leave_flag=1))))
ORDER BY fname
在查询中使用 IN 语句会花费无尽的时间。但是当我用存在替换它时,它会给出不同的输出。
任何帮助将不胜感激。