group by ROLLUP(A, B, C),首先会对(A、B、C)进行GROUP BY,然后对(A、B)进行GROUP BY,
然后是(A)进行GROUP BY,最后对全表进行GROUP BY操作
然后是(A)进行GROUP BY,最后对全表进行GROUP BY操作
GROUP BY CUBE(A, B, C),则首先会对(A、B、C)进行GROUP BY,
然后依次是(A、B),(A、C),(A),(B、C),(B),(C),最后对全表进行GROUP BY操作。
*******************group rollup*****************
然后依次是(A、B),(A、C),(A),(B、C),(B),(C),最后对全表进行GROUP BY操作。
*******************group rollup*****************
SELECT deptno, job, sum(sal)
FROM emp
GROUP BY ROLLUP(deptno,job);
FROM emp
GROUP BY ROLLUP(deptno,job);
SELECT deptno, job, sum(sal)
FROM emp
GROUP BY deptno,job;
FROM emp
GROUP BY deptno,job;
*******************group cube***************
SELECT deptno, job, sum(sal)
FROM emp
GROUP BY CUBE(deptno,job);
FROM emp
GROUP BY CUBE(deptno,job);
grouping:
SELECT deptno, job, sum(sal), grouping(job),grouping(deptno)
FROM emp
GROUP BY ROLLUP(deptno,job);
FROM emp
GROUP BY ROLLUP(deptno,job);
SELECT deptno, job, sum(sal), grouping(job),grouping(deptno)
FROM emp
GROUP BY CUBE(deptno,job);
FROM emp
GROUP BY CUBE(deptno,job);
***************grouping set 分组求统计再联合*******************************
SELECT deptno, job,
mgr,avg(sal)
FROM emp
GROUP BY GROUPING SETS ((deptno,job), (job,mgr));
mgr,avg(sal)
FROM emp
GROUP BY GROUPING SETS ((deptno,job), (job,mgr));
select * from emp order by job;
复合列:
SELECT deptno, job, mgr,
SUM(sal)
FROM emp
GROUP BY ROLLUP( deptno,(job, mgr));
SUM(sal)
FROM emp
GROUP BY ROLLUP( deptno,(job, mgr));
SELECT deptno, job,
SUM(sal)
FROM emp
GROUP BY ROLLUP((deptno,job));
SUM(sal)
FROM emp
GROUP BY ROLLUP((deptno,job));
SELECT deptno, job,
SUM(sal)
FROM emp
GROUP BY deptno,job;
SUM(sal)
FROM emp
GROUP BY deptno,job;
SELECT deptno, job,
SUM(sal)
FROM emp
GROUP BY ROLLUP(deptno,job);
SUM(sal)
FROM emp
GROUP BY ROLLUP(deptno,job);
***********************
SELECT deptno, job, mgr,
SUM(sal),grouping(deptno),grouping(job)
FROM emp GROUP BY deptno,
ROLLUP(job),
CUBE(mgr);
SELECT deptno, job, mgr,
SUM(sal),grouping(deptno),grouping(job)
FROM emp GROUP BY deptno,
ROLLUP(job),
CUBE(mgr);