DISCLAIMER: Before starting this tutorial, it's highly recommended that you download an RDBMS to follow along.
We recommend using either PostgreSQL, MS SQL Server, or MySQL.
Aggregating data is a very popular task in data analytics. Because of this, SQL provides various
extensions to the GROUP BY Clause to give you more power with your aggregations. This tutorial will cover the
following learning objectives:
SELECT [column_name1], SUM([column_name2])
FROM [table_name]
GROUP BY ROLLUP ([column_name1]);
SELECT [col1], [col2], [col3], SUM([col4])
FROM [table_name]
GROUP BY [col1],
ROLLUP ([col2], [col3])
SELECT [column_name1], [column_name2], SUM([column_name3]) AS [alias1]
FROM [table_name]
GROUP BY CUBE([column_name1], [column_name2]);
SELECT [column_name1], [column_name2], SUM([column_name3]) AS [alias]
FROM [table_name]
GROUP BY GROUPING SETS
(([column_name1]), ([column_name2]), ([column_name1], [colUmn_name2]));
Congratulations! You just completed the GROUP BY Extensions Tutorial! To help test your knowledge, let's
use the "Sales" database to practice using the GROUP BY extensions covered in this tutorial. This exercise is based on the exercise of
the previous tutorial.
**It's highly recommended that you
complete the exercise outlined in the previous tutorial before beginning this exercise.**
The Database used in this exercise includes data on hundreds of Lego sets and their associated parts, colors, and themes.
Have any issues with the above exercise? Post your question on Discord!