Aggregate Examples

AVAILABLE API VERSION
API v58.0 and later

Use aggregate functions to analyze your query results. You can use aggregate functions without a groupBy argument, such as using totalCount to find the total number of query results or using the avg function to find the average amount for all opportunities. You can also use aggregation functions with a groupBy argument, like finding the average amount of all opportunities by campaign.

Return the total number of account records.

The previous query returns this response.

The previous query is similar to the following SOQL statement.

The previous query is similar to the following SOQL statement.

You can't simultaneously query both the record and aggregate fields within RecordAggregate. Query the records and aggregation separately like this.

The previous query is similar to the following SOQL statement.

The previous query is similar to the following SOQL statement.

Grouping Examples

SOQL and SOSL Reference: Aggregate Functions