0

我创建了以下视图,

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

它工作正常并给出了预期的结果。但问题是执行和给出结果需要时间。有时它也会给出错误,比如超时等。你能帮我解决这个问题吗?

4

1 回答 1

0

也许你应该重组你的数据库?例如,创建将表示连接的表。如果您不关心时间,您可以通过创建临时表虚拟表(也称为视图)来避免超时错误。避免这样复杂和嵌套的表达式。

于 2012-06-21T07:10:20.677 回答