查询emp表中每个员工的名称及其所在部门的平均工资。
展开全部
SQL> 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
----- ---------- --------- ----- ----------- --------- --------- ------ ----------
7369 SMITH CLERK 7902 1980-12-17 800.00 20 2175
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30 1566.66666
7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30 1566.66666
7566 JONES MANAGER 7839 1981-4-2 2975.00 20 2175
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30 1566.66666
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30 1566.66666
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10 2916.66666
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20 2175
7839 KING PRESIDENT 1981-11-17 5000.00 10 2916.66666
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30 1566.66666
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20 2175
7900 JAMES CLERK 7698 1981-12-3 950.00 30 1566.66666
7902 FORD ANALYST 7566 1981-12-3 3000.00 20 2175
7934 MILLER CLERK 7782 1982-1-23 1300.00 10 2916.66666
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO PJSAL
----- ---------- --------- ----- ----------- --------- --------- ------ ----------
7369 SMITH CLERK 7902 1980-12-17 800.00 20 2175
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30 1566.66666
7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30 1566.66666
7566 JONES MANAGER 7839 1981-4-2 2975.00 20 2175
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30 1566.66666
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30 1566.66666
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10 2916.66666
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20 2175
7839 KING PRESIDENT 1981-11-17 5000.00 10 2916.66666
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30 1566.66666
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20 2175
7900 JAMES CLERK 7698 1981-12-3 950.00 30 1566.66666
7902 FORD ANALYST 7566 1981-12-3 3000.00 20 2175
7934 MILLER CLERK 7782 1982-1-23 1300.00 10 2916.66666
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你该给出用到的表结构和表之间的关系。
select a.员工姓名,b.avg_gz as 平均工资
from emp a,(select 部门,avg(工资) as avg_gz from emp group by 部门) as b
where a.部门=b.部门
select a.员工姓名,b.avg_gz as 平均工资
from emp a,(select 部门,avg(工资) as avg_gz from emp group by 部门) as b
where a.部门=b.部门
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
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;
~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询