我得到无效的列名“平均”。当我在没有别名的情况下写作时,它可以工作。但是我的条件太多了。
SELECT
ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES.EMPLOYEEID,
Employees.EMPLOYEENAMESURNAMEFORMAT AS LastFirstName,
(CAST(SUM(EVALUATION) AS FLOAT)
/
(SELECT TOP 1
COUNT(*)
FROM ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES
WHERE DATE BETWEEN '2013-01-01' AND '2013-12-12' AND TYPE=2 AND SUPERVISORID=1020 GROUP BY EmployeeID )) AS AVERAGE,
CASE WHEN AVERAGE=1
THEN 'GOOD' END AS EVALUATION
FROM ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES INNER JOIN Employees
ON ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES.EMPLOYEEID=Employees.EmployeeID
WHERE DATE BETWEEN '2013-01-01' AND '2013-12-12' AND TYPE=2 AND ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES.SUPERVISORID=1020 AND ACTIVESTATUS=1
GROUP BY
ST_LAWERP_PERFORMANCE_EVALUATION_ENTRIES.EMPLOYEEID,
EMPLOYEENAMESURNAMEFORMAT