Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add intro with toc & link to Group By doc; fix count

This document describes enhanced aggregation features for the GROUP BY clause of SELECT statements.

Table of Contents

For general information about GROUP BY, see GroupBy in the Language Manual.

GROUPING SETS clause

The GROUPING SETS clause in GROUP BY allows us to specify more than one GROUP BY options in the same record set. All GROUPING clause query can be logically expressed in terms of several GROUP BY queries connected by UNION. Table-1 shows several such equivalent statements. This is helpful in forming the idea of the GROUPING SETS clause. A blank set ( ) in the GROUPING SETS clause calculates the overall aggregate.

...

Column1 (key)

Column2 (value)

1

NULL

1

1

2

2

3

3

3

NULL

4

5

The following query: SELECT key, value, GROUPING__ID, count(star) (*) from T1 GROUP BY key, value WITH ROLLUP
will have the following results.

...