Introduction
GROUP BY – Recap
Summary
20. Summary

Instruction

Alright, let's wrap things up!

  1. 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 ()
    
  2. By changing the order of columns inside ROLLUP, we change the grouping levels created.
  3. Not all columns must be included inside ROLLUP. Those outside its parentheses will always be used for grouping.
  4. We can use GROUPING_ID(...) in the SELECT clause to show the grouping level for each row.
  5. We can use COALESCE(ColumnName, SubstituteValue) to show the SubstituteValue when ColumnName is NULL.
  6. The GROUPING(ColumnName) function shows if the ColumnName column is used in the grouping.

Now, how about a short quiz?

Exercise

Click Next exercise to continue.