Instruction
Alright, let's wrap things up!
GROUP BY ROLLUP()works by creating additional rows with fewer grouping columns, as shown below:GROUP BY ROLLUP (A, B, C) = GROUP BY (A, B, C) + GROUP BY (A, B) + GROUP BY (A) + GROUP BY ()
- By changing the order of columns inside
ROLLUP, we change the grouping levels created. - Not all columns must be included inside
ROLLUP. Those outside its parentheses will always be used for grouping. - We can use
GROUPING_ID(...)in theSELECTclause to show the grouping level for each row. - We can use
COALESCE(ColumnName, SubstituteValue)to show theSubstituteValuewhenColumnNameisNULL. - The
GROUPING(ColumnName)function shows if theColumnNamecolumn is used in the grouping.
Now, how about a short quiz?
Exercise
Click to continue.



