Tuesday, October 2, 2018

SQL Rollup and Cube

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);
Multiple column group by with Rollup and Cube :

SQL>select deptno,job,count(*) from emp
group by rollup(deptno,job)
order by 1;
 
SQL>select deptno,job,count(*) from emp
group by cube(deptno,job)
order by 1;

No comments:

Post a Comment

SQL Index

Index Index :-  Index is a data structure like table.Index store column data(On which index created) with row identifier rowid.  Databa...