Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 

In continuation to my previous blog on introducing Except Set, in this blog, I would like to introduce GROUPING SET function. I am writing this blog to share my knowledge and experience with people who would like to get introduced to the GROUPING SETS function. With this blog, I hope people would find writing GROUPING SET SQL easier and it might save their time as well.


GROUPING SETS allows specifying precisely which aggregations we want to compute. The GROUPING SETS operator aggregates only specified groups
instead of full sets of aggregations.


GROUPING SET is able to generate a result set that can be generated by a UNION ALL of multiple simple GROUP BY clauses.


For Example:

As can be seen in the above example, there are four sets specified in the above query and are highlighted in the above screenshot.

On execution of the above query the result set generated by the query will aggregate the results into four sets as showcased in the next screenshots:

Result set for group set

is:

As can be seen in the above example, there are four sets specified in the above query and are highlighted in the above screenshot. On execution of the above query the result set generated by the query will aggregate the results into four sets as showcased in the next screenshots:

Result set for group set

is:

The ‘?’ in the above result set indicates that all NAME1 for each set of BUKRS, KOKRS, LAND1 have been grouped together.

Result set for group set

is:

The ‘?’ in the above result set indicates that all LAND1 for each set of BUKRS, KOKRS, NAME1 have been grouped together.

Result set for group set

is:

The ‘?’ in the above result set indicates that all LAND1 and NAME1 for each set of BUKRS, KOKRS have been grouped together.

Has this instructional blog helped you in understanding GROUPING SETS? If so, I would highly appreciate you letting me know, and providing any feedback. The readers could stay tuned for my upcoming blog as I introduce using "WorkDaysBetween and AddWorkdays function" and how to use them in HANA system.