查询emp表中工资超过其所在部门平均工资的员工的名称。
展开全部
select a.员工姓名
from emp a,(select 部门,avg(工资) as avg_gz from emp group by 部门) as b
where a.部门=b.部门 and a.工资>b.avg_gz
from emp a,(select 部门,avg(工资) as avg_gz from emp group by 部门) as b
where a.部门=b.部门 and a.工资>b.avg_gz
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select emp.*, b.pjsal from emp,(select emp.* ,a.pjsal from emp,(select avg(sal) pjsal,deptno from emp group by deptno) a where a.deptno=emp.deptno) b where emp.sal>b.pjsal and emp.empno=b.empno;
首先用select emp.* ,a.pjsal from emp,(select avg(sal) pjsal,deptno from emp group by deptno)a where a.deptno=emp.deptno查出每个部门的平均工资
然后使得每个人的工资和平均工资比较
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO PJSAL
----- ---------- --------- ----- ----------- --------- --------- ------ ----------
7839 KING PRESIDENT 1981-11-17 5000.00 10 2916.66666
7902 FORD ANALYST 7566 1981-12-3 3000.00 20 2175
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20 2175
7566 JONES MANAGER 7839 1981-4-2 2975.00 20 2175
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30 1566.66666
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30 1566.66666
首先用select emp.* ,a.pjsal from emp,(select avg(sal) pjsal,deptno from emp group by deptno)a where a.deptno=emp.deptno查出每个部门的平均工资
然后使得每个人的工资和平均工资比较
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO PJSAL
----- ---------- --------- ----- ----------- --------- --------- ------ ----------
7839 KING PRESIDENT 1981-11-17 5000.00 10 2916.66666
7902 FORD ANALYST 7566 1981-12-3 3000.00 20 2175
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20 2175
7566 JONES MANAGER 7839 1981-4-2 2975.00 20 2175
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30 1566.66666
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30 1566.66666
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-03-29
展开全部
select * from ( select emp.*, avg(emp.sal) over (partition by emp.deptid) as avgsal from emp) a where a.sal>a.avgsal order by emp.deptid;
~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询