Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
GROUP BY – Recap


Alright. Let's explain where the values of Grouping_ID (0, 1, 3, 7) come from.

Grouping_ID(A, B, C) uses binary numbers to represent which columns from (A, B, C) were used in the ROLLUP clause. Each column (A, B, C) is represented as either a 1 (used for aggregation) or a 0 (not used for aggregation). In this way, the database creates a binary number, such as 011 or 001, which is then converted into an integer, as shown below:


As usual, it's time you wrote a query yourself!


Show how much was spent on average for each Category on each day, on each day in general, and in general among all days and categories.

Show the following columns: GroupingId (depending on the DeliveryDate and Category, respectively), Category, DeliveryDate, and the average TotalPrice (rename the column to AvgPrice).

Order the results by the GroupingId value. This way, related results are displayed next to each other.

Stuck? Here's a hint!


GROUPING_ID(DeliveryDate, Category) AS GroupingId