Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Calculate the Average Salary by Department?

User_FZOVQMar 21 2022

Hi so I am running the below query and and it show my the salary by department and also min and max salary. However, when I tried to use AVG to find the average salary by each DEPARTMENTS it throw me an error. I wonder if anyone has any advice how to sort that? Thanks
SELECT
E.EMPLOYEE_ID,
E.FIRST_NAME,
E.LAST_NAME,
E.SALARY,
D.DEPARTMENT_ID,
D.DEPARTMENT_NAME,
E.SALARY,
j.max_salary,
j.min_salary
-- AVG(SALARY) AS AVERAGE_SALARY
FROM EMPLOYEES E
JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
JOIN JOBS J
ON E.JOB_ID = J.JOB_ID
image.pngSELECT
E.EMPLOYEE_ID,
E.FIRST_NAME,
E.LAST_NAME,
E.SALARY,
D.DEPARTMENT_ID,
D.DEPARTMENT_NAME,
E.SALARY,
j.max_salary,
j.min_salary,
AVG(SALARY) AS AVERAGE_SALARY
FROM EMPLOYEES E
JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
JOIN JOBS J
ON E.JOB_ID = J.JOB_ID
image.png

Comments
Post Details
Added on Mar 21 2022
2 comments
548 views