Skip to Content

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:

Grp1.png

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:Grp2.png

Grp3.png

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

Grp4.png

is:

Grp5.png

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

Grp6.png

is:

Grp7.png

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

Grp8.png

is:

Grp9.png

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.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply