top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between Rollup ad cube?

+3 votes
578 views

What is the difference between rollup and cupe, which is good to use also give example to solve?
Also if someone can explain about what is grouping function?

posted Apr 3, 2015 by Santosh Kumar Panigrahi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Thanx for the link...superb like

1 Answer

0 votes

The ROLLUP extends GROUP BY to return a row containing a subtotal for each group of rows, plus a row containing a total for all the groups.

E.g.

SELECT division_id, job_id, SUM(salary)
FROM employees2
GROUP BY ROLLUP(division_id, job_id)
ORDER BY division_id, job_id;

Output

DIV JOB SUM(SALARY)
--- --- -----------
BUS MGR  530000
BUS PRE  800000
BUS WOR  280000
BUS      1610000
OPE ENG  245000
OPE MGR  805000
OPE WOR  270000
OPE      1320000
SAL MGR  4446000
SAL WOR  490000
SAL      4936000
         8881000

The CUBE clause extends GROUP BY to return rows containing a subtotal for all combinations of columns, plus a row containing the grand total.

e.g.

SELECT division_id, job_id, SUM(salary)
FROM employees2
GROUP BY CUBE(division_id, job_id)
ORDER BY division_id, job_id;

DIV JOB  SUM(SALARY)
--- ---  -----------
BUS MGR   530000
BUS PRE   800000
BUS WOR   280000
BUS       1610000
OPE ENG   245000
OPE MGR   805000
OPE WOR   270000
OPE       1320000
SAL MGR   4446000
SAL WOR   490000
SAL       4936000
ENG       245000
MGR       6246000
PRE       800000
TEC       115000
WOR       1475000
          8881000
answer Apr 3, 2015 by Salil Agrawal
...