ROLLUP & CUBE FUNCTION
Rollup and Cube :- Rollup and cube are used with group by clause to get the total of values.
Note :-For single column rollup and cube will provide the same result but with more than one column group by both will provide the different result.
Single column group by with Rollup and Cube :
SQL>select job,count(*) from emp
group by ROLLUP(job);
SQL>select job,count(*) from emp
group by cube(job);
SQL>select deptno,job,count(*) from emp
group by rollup(deptno,job)
order by 1;
group by ROLLUP(job);
SQL>select job,count(*) from emp
group by cube(job);
Multiple column group by with Rollup and Cube :
group by rollup(deptno,job)
order by 1;
SQL>select deptno,job,count(*) from emp
group by cube(deptno,job)
order by 1;
group by cube(deptno,job)
order by 1;
No comments:
Post a Comment