首页 > 解决方案 > 找出他们部门内平均工资超过 8000 的员工

问题描述

我试图找到员工的平均工资高于8000他们的department

我得到的avg(salary)部门内大于8000但无法显示名称

select avg(salary) from employees group by department_id having avg(salary)> 8000

它显示员工姓名

标签: oraclegreatest-n-per-group

解决方案


尝试这个:

Select department_id, emp_name, salary from
(select department_id, emp_name, salary, avg(salary) over(partition by department_id) as avg_salary 
from employees)
Where avg_salary >= 8000 
AND salary >= 8000; -- ADDED THIS CONDITION

以上查询将返回部门内所有员工平均工资大于8000的员工,包括部门id、员工姓名和工资。

干杯!!


推荐阅读