0

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

0 回答 0