我需要选择工资高于按部门分组的平均工资的员工。
SELECT * FROM employees
WHERE salary > (SELECT AVG(salary), department_id FROM employees GROUP BY department_id)
它失败了,因为它返回了我 2 列。
我试过这个查询:
SELECT * FROM employees
HAVING salary > AVG(salary)
GROUP BY (department_id)
现在我收到错误消息:ORA-00979: not a GROUP BY expression