I am writing a query to find employees who earn greater than the average salary within their department. I need to display the employee ID, salary, department id, and averag
select employee_id, salary, department_id, avg_sal
from
(
SELECT employee_id, salary, department_id,
round(avg(salary) over (partition by department_id), 2) avg_sal
from emp
)
where salary > avg_sal
order by avg_sal desc