How to Use the Grouping Function

  • google plus

In Brief...

The grouping function returns a value of 1 when a grand total for groups is displayed on a group by clause with the rollup function. Otheriwse, the grouping function will return a 0. Therefore, this function allows you to distinguish a group total from a grand total for multiple groups.

Take our Advanced Oracle SQL Queries course for free.

See the Course Outline and Register

Instructions

To learn how to use the grouping function, follow these steps:

  1. You'll need to download and install Oracle 12c. The instructions for the setup can be found in How to use sample schemas. Follow steps 1 through 4 before proceeding to the next step.
  2. The following query uses the grouping function to display the value of the function on group total lines and on the final overall count:
    Number of employees in each department using grouping
    Note that the value of the function is 0 on group total report lines and is 1 on the final aggregate total of all groups printed at the end of the report.

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, XML, Windows, Java, Adobe, HTML5, JavaScript, Angular, and much more. Check out our complete course catalog.

Categories

Courses

Author: Stephen Withrow

Stephen has over 30 years' experience in training, development, and consulting in a variety of technology areas including Java, C, C++, XML, JavaScript, AJAX, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen is a published writer in both technical and non-technical endeavors. Stephen received an undergraduate degree in Computer Science and Physics from Florida State University.

Discuss