GROUPING SETS

Function

This statement is used to generate the cross-table row and achieve the cross-statistics of the GROUP BY field.

Syntax

1
2
3
SELECT attr_expr_list FROM table_reference
  GROUP BY col_name_list
  GROUPING SETS(col_name_list);

Keyword

GROUPING SETS is the expansion of GROUP BY. For example:

Precautions

Example

To generate the cross-table row according to the group_id and job fields and return the total salary on each aggregation condition, run the following statement:

1
2
3
SELECT group_id, job, SUM(salary) FROM group_test
  GROUP BY group_id, job
  GROUPING SETS (group_id, job);