ROLLUP
Function
This statement is used to generate the aggregate row, super-aggregate row, and the total row. The statement can achieve multi-layer statistics from right to left and display the aggregation of a certain layer.
Syntax
1 2 3 |
SELECT attr_expr_list FROM table_reference
GROUP BY col_name_list
WITH ROLLUP;
|
Keyword
- Counting the (a, b, c) combinations
1 2
SELECT a, b, c, sum(expression) FROM table GROUP BY a, b, c;
- Counting the (a, b) combinations
1 2
SELECT a, b, NULL, sum(expression) FROM table GROUP BY a, b;
- Counting the (a) combinations
1 2
SELECT a, NULL, NULL, sum(expression) FROM table GROUP BY a;
- Total
1
SELECT NULL, NULL, NULL, sum(expression) FROM table;
Precautions
The to-be-grouped table must exist. If this statement is used to group a table that does not exist, an error is reported.
Example
To generate the aggregate row, super-aggregate row, and total 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
WITH ROLLUP;
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.