The difference between rollup and cube in Oracle GROUP by:
Oracle's GROUP BY statement supports rollup and cube statements in addition to the most basic syntax.
In the case of rollup (a, B, c), group by IS performed on (a, B, c), then group by (A, B), then (a) group by, and finally group by operations on the whole table;
In the case of group by CUBE (A, B, c), the group by IS first performed (A, B, C), followed by (A, B), (A, C), (a), (b, C), (b), (c), and finally the group by operation of the whole table.
Test data:
/*
Oracle's GROUP BY statement supports rollup and cube statements in addition to the most basic syntax.
*/
--Create a table
Create Table fzq ( varchar ),varchar(2), Kemu varchar (4), varchar (3)
Test Table
--Inserting data
Insert intoFzqValues (' One','1','Mathematics',' -');Insert intoFzqValues (' One','1','language',' the'); Insert intoFzqValues (' A','1','Mathematics',' -'); Insert intoFzqValues (' A','1','language',' the'); Insert intoFzqValues (' A','2','Mathematics',' -'); Insert intoFzqValues (' A','2','language',' the'); Insert intoFzqValues (' -','2','Mathematics',' the'); Insert intoFzqValues (' -','2','language','98');Commit;
test Data
- Select Calss,name,sum (Chengji) from FZQ Group by Calss,name;
- Select Calss,name,sum (Chengji) from FZQ Group by Cube (calss,name) order by CALSS;
- Select Calss,name,sum (Chengji) from FZQ GROUP by rollup (calss,name) Order by CALSS;
- Select Calss,name,sum (Chengji) from FZQ Group by grouping sets (Calss,name);
How to use and distinguish between cube and rollup sentences in Oracle GROUP by