The query is the same as GROUP BY except we added a new CUBE sub-clause after GROUP BY clause. The query statement generates all possible grouping sets based on the dimension columns specified in CUBE. If the number of columns specified in the CUBE is n, then you will get the result in 2n combinations.