select ds.deptno, t2.grade
from (select deptno, avg(sal) as avgsal from emp group by deptno) ds
left join salgrade t2
on ds.avgsal between t2.losal and t2.hisal
select t1.deptno, t2.grade
from (select deptno, avg(sal) as avgsal from emp group by deptno) t1,
salgrade t2
where t1.deptno = t2.deptno
and t1.avgsal between t2.losal and t2.hisal