我创建了以下视图,
SELECT
currency_cd, SUM(comprate) AS salary, employee_code,
(SELECT SUM(c.comprate) AS Expr1
FROM dbo.employees_compensation AS c
INNER JOIN
(SELECT MAX(id) AS id, comp_ratecd
FROM dbo.employees_compensation
WHERE (effdt = (SELECT MAX(effdt) AS Expr1
FROM dbo.employees_compensation AS employees_compensation_1
WHERE (employee_code = b.employee_code)
)
) AND (employee_code = b.employee_code)
GROUP BY
comp_ratecd) AS a ON c.id = a.id) AS salary1
FROM
dbo.employees_compensation AS b
GROUP BY
currency_cd, employee_code
它工作正常并给出了预期的结果。但问题是执行和给出结果需要时间。有时它也会给出错误,比如超时等。你能帮我解决这个问题吗?