In Oracle, we may prefer to use the group by clause, but many people may not know that in the group by clause, we can perform super aggregate group search. At this time, we use two keywords, A rollup and a cube.
Rollup is grouped from right to left based on the group by condition. That is to say, if two group by conditions exist, the group by operation is performed once based on only one condition on the right, then, group by is performed based on the two conditions on the right.
Cube is more comprehensive. In addition to grouping from the right to the left, it will be further grouped from the left to the right. Therefore, there will be more result sets after cube. The two grouping syntaxes are as follows.
Select
Col1,
Col2,
Sum (Col3)
From
TBL
Group By Rollup (col1, col2)
Select
Col1,
Col2,
Sum (Col3)
From
TBL
Group By Cube (col1, col2)