I’m trying to get the hang of the ‘Group By Grouping Sets’ syntax, and I’m always having to look it up. Here is a quick little bit of example code that will get you started
GROUPING SETS ( )
Specifies multiple groupings of data in one query. Only the specified groups
are aggregated instead of the full set of aggregations that are generated by
CUBE or ROLLUP. The results are the equivalent of UNION ALL of the specified
groups. GROUPING SETS can contain a single element or a list of elements.
GROUPING SETS can specify groupings equivalent to those returned by ROLLUP or
CUBE. The <grouping set item list> can contain ROLLUP or
CUBE.
( )
The empty group generates a total