日期:2014-05-16 浏览次数:20444 次
查询每个部门的平均工资(而且显示部门名称)。
? 1* select deptno,avg(sal) from emp group by deptno having (deptno in (select deptno from dept))
SQL> /
??? DEPTNO?? AVG(SAL)
---------- ----------
??????? 30 1566.66667
??????? 20?????? 2175
??????? 10 2916.66667
SQL> select deptno,avg(sal) from emp group by deptno;
??? DEPTNO?? AVG(SAL)
---------- ----------
??????? 30 1566.66667
??????? 20?????? 2175
??????? 10 2916.66667
就是查找每个部门名称和部门平均工资:
select dname,avg(sal) from (select dname,emp.* from emp,dept where dept.deptno=emp.deptno) group by
dname;
DNAME??????????? AVG(SAL)
-------------- ----------
ACCOUNTING???? 2916.66667
RESEARCH???????????? 2175
SALES????????? 1566.66667