oracle 部门平均工资〈50000的员工数

wsxa1bj1  于 2022-12-03  发布在  Oracle
关注(0)|答案(1)|浏览(145)

我对听起来像这样的任务感到困惑:

Display the number of employees whose average half-year salary for the department in which they work does not exceed 50,000

我不确定我需要使用的语法和命令序列
SELECT COUNT(EMPLOYEE_ID) AS 'Total' FROM HR.EMPLOYEES GROUP BY DEPARTMENT_ID WHERE AVG(SALARY*6) <= 50000
我试过了,但不知道如何正确编写查询
这是一个DB的照片(我不能提供代码片段)

5sxhfpxr

5sxhfpxr1#

可以使用分析函数计算平均薪资。
--未测试

SELECT * FROM (
SELECT employee_id,   department_id, 
    round(avg(salary) over (partition by department_id), 2) avg_sal
  from HR.EMPLOYEES
) WHERE avg_sal > 50000;

相关问题