SELECT every employee that has a higher salary than the AVERAGE of his department

后端 未结 7 1347
臣服心动
臣服心动 2021-01-13 23:46

I have only 1 table named EMPLOYEE on my database with the 3 following collumns:

Employee_Name, Employee_Salary, Department_ID
7条回答
  •  情话喂你
    2021-01-14 00:25

    Assuming Postgres,

    Try This

    select e1.* from emp e1  inner join (select avg(sal) avg_sal,dept_id from emp group by dept_id) as e2 on e1.dept_id=e2.dept_id and e1.sal>e2.avg_sal
    

提交回复
热议问题