我试图只输出平均工资高于公司平均工资的部门。
SELECT Departments.DEPARTMENT_NAME
FROM Employees inner join departments
ON Employees.DEPARTMENT_ID = Departments.DEPARTMENT_ID
WHERE (SELECT AVG(CAST(Employees.salary AS decimal))
GROUP BY Employees.DEPARTMENT_ID) > (SELECT AVG(CAST(Employees.salary AS decimal)))
GROUP BY Departments.DEPARTMENT_NAME;
答案 0 :(得分:1)
我认为这可能是你想要的:
SELECT D.DEPARTMENT_NAME
FROM Employees E
INNER JOIN Departments D ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
GROUP BY D.DEPARTMENT_NAME
HAVING AVG(CAST(E.Salary AS decimal)) >
(SELECT AVG(CAST(Salary AS decimal)) FROM Employees)