select A.* from emp a,(select deptid,avg(salary) salaryfrom empgroup by deptid) bwhere a.deptid = b.deptid and a.salary > b.salary