select s.deptno,s.dname,count(t.empno) from emp t,dept s where t.deptno=s.deptno group by s.deptno,s.dname having count(t.empno) > (select count(empno)/count(distinct deptno) from emp )
错误在于avg(count(empno))这里其实是按部门计数、按部门求平均两步查询,不能在一次子查询里实现。其实可以跳出avg(count(,直接用count总人数除count部门数来求平均:select count(distinct empno)/count(distinct deptno)