sql - Correlated subquery to find employees earning more than average salary in their departments -


i writing oracle query find employees earn more average salary within departments. need display last_name,employee_id, salary, department_id , average salary of department. have written query not getting desired answer. can please tell me, making mistake

select last_name,employee_id,salary,department_id,avg(salary)    employees e1  salary > (select avg(salary)                     employees e2                    e1.department_id=e2.department_id)  group last_name,employee_id,salary,department_id 

with med          (select department_id, avg(salary) avgsalary             employees            group department_id)         select last_name, employee_id, salary, e.department_id, avgsalary           employees e, med m          e.department_id = m.department_id , e.salary > m.avgsalary 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -