Only this week, get the SQL Complete Track of 9 courses in a special prize of $330$89!
Introduction
GROUPING SETS
Summary

## Instruction

Good job! Just like CUBE and ROLLUP, GROUPING SETS work well with GROUPING_ID:

SELECT
CustomerId,
RepairCenter,
AVG(RepairDuration) AS AvgRepairDuration
FROM WarrantyRepair
GROUP BY GROUPING SETS
(
(CustomerId, RepairCenter),
)


The order of the columns in GROUPING_ID is up to you, but note that different values will be generated if you change the column order.

## Exercise

Find the maximal principal amount for the following grouping levels:

1. SalesPerson
2. Year
3. Country

Show the following columns in the query result: GroupingId, SalesPerson, Year, Country, and MaxPrincipal. The GROUPING_ID() should have the following columns in its parentheses: SalesPerson, Year, and Country.

### Stuck? Here's a hint!

This template may come in handy:

SELECT
GROUPING_ID(A, B) AS GroupingId,
A,
B,
...
FROM X
GROUP BY GROUPING SETS
(
(A),
(B)
)