desc emp;


Name                                            Null?            Type
----------------------------------------- -------- ----------------------------
EMPNO                              NOT NULL  NUMBER(4)
ENAME                                    VARCHAR2(10)
JOB                                    VARCHAR2(9)
MGR                                    NUMBER(4)
HIREDATE                                    DATE
SAL                                    NUMBER(7,2)
COMM                                    NUMBER(7,2)
DEPTNO                                    NUMBER(2)


既要显示部门的平均工资,也要显示岗位的平均工资。那么可以使用GROUPING SET函数。

SQL> select deptno,job,avg(sal) from emp group by grouping sets(deptno,job);

DEPTNO JOB AVG(SAL)
---------- --------- ----------
CLERK 1037.5
SALESMAN 1400
PRESIDENT 5000
MANAGER 2758.33333
ANALYST 3000
30 1566.66667
20 2175
10 2916.66667

8 rows selected.

0 评论

发表评论

订阅: 博文评论 (Atom)