SQL中这道题怎么做啊?

2025-04-05 02:56:18
推荐回答(2个)
回答1:

select * from (
select deptno, count(ename) as shuli, avg(sal) as 平均工资 from emp as tA where sal > (select avg(sal) from emp where deptno = tA.deptno) group by deptno
) as t where shuli > 1

回答2:

select deptno, sum(case when e1.sal>avg(e2.sal) then 1 else 0) as peoplecount, avg(e2.sal)
from emp e1 join emp e2
on e1.deptno=e2.deptno
having sum(case when e1.sal>avg(e2.sal) then 1 else 0)>=1
group by e1.deptno,e2.deptno
order by e2.deptno