Grouping Examples

AVAILABLE API VERSION
API v58.0 and later

You can use aggregate functions without a groupBy argument or use them with a groupBy argument with optional types CUBE or ROLLUP.

You can also use aggregation function with a groupBy argument, like finding the average amount of all your opportunities by campaign.

The previous query is similar to the following SOQL statement.

The previous query is similar to the following SOQL statement.

The previous query is similar to the following SOQL statement.

The previous query is similar to the following SOQL statement.

SOQL and SOSL Reference: GROUP BY CUBE