---
schema_version: "1"
id: 6520541f2743f8fdba40398b0e54ef5be783470e5a5ca46d54386ab8f8834f22
title: Aggregate Your Query Results
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/guides/get-started-dc-sql/aggregate-query-results.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/aggregate-query-results.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 0b99927b6204c3d11cc14fc5f374ff0aaebda9b6a5f42830d77e30be3d520cb3
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# Aggregate Your Query Results

For large datasets, you don’t want to inspect each individual dataset. To see high-level insights across a dataset, aggregate your query.

For example, you can get the average age of customers, the total sales amount for a product, or the count of customers by geographical location. To aggregate data in the returned result set, use aggregate functions in the `SELECT` clause. For a list of aggregate functions, see [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.html).

This query returns the count of individuals whose first name starts with ‘E’.

```
SELECT COUNT("ssot__Id__c") AS count1
FROM "ssot__Individual__dlm"
WHERE "ssot__FirstName__c" LIKE 'E%'

```

The query returns one row containing the aggregated count.

| `count1` |
| -------- |
| 2        |

Alternatively, you can get the same count for the unified individual records by querying UnifiedIndividual\_\_dlm.

```
SELECT COUNT("ssot__Id__c") AS count1
FROM "UnifiedIndividual__dlm"
WHERE "ssot__FirstName__c" LIKE 'E%'

```

Based on the sample data, we get the same aggregate result.

| `count1` |
| -------- |
| 2        |

The `GROUP BY` clause is often useful with aggregate results because it groups the query results by a category.

This example uses `GROUP BY` to return the count of addresses in ssot\_\_ContactPointAddress\_\_dlm by country.

```
SELECT "ssot__CountryId__c", COUNT("ssot__Id__c") AS TotalAddresses
FROM "ssot__ContactPointAddress__dlm"
GROUP BY "ssot__CountryId__c"

```

This query output shows sample results.

| `TotalAddresses` | `ssot__CountryId__c` |
| ---------------- | -------------------- |
| 3                | France               |
| 23               | USA                  |
| 1                | Taiwan               |
| 15               | Japan                |

To filter the results of the aggregated query to get the top counts of addresses—only the counts that are greater than 10—you can filter the aggregated result with the `HAVING` clause.

This example aggregates the addresses in ssot\_\_ContactPointAddress\_\_dlm by the country ID and returns the records whose count of addresses by country is greater than 10.

```
SELECT COUNT("ssot__Id__c") AS TotalAddresses,"ssot__CountryId__c"
FROM "ssot__ContactPointAddress__dlm"
GROUP BY "ssot__CountryId__c"
HAVING COUNT("ssot__Id__c") > 10

```

This query output shows sample results. In this case, there are more than 10 addresses for the United States and Japan.

| `TotalAddresses` | `ssot__CountryId__c` |
| ---------------- | -------------------- |
| 23               | USA                  |
| 15               | Japan                |

## Common Aggregate Functions

Aggregate functions compute a single result from a set of input values. This section contains some commonly used aggregate functions. To see the full list of available aggregate functions, see [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.html) in the Data 360 SQL Reference.

- `SUM(expression)`

  - : Returns the sum of `<expression>` of all input values.

- `AVG(expression)`

  - : Returns the average (arithmetic mean) of all input values.

- `COUNT(*)`

  - : Returns the number of input rows.

- `MIN(expression)`

  - : Returns the minimum value of `<expression>` of all input values.

- `MAX(expression)`
  - : Returns the maximum value of `<expression>` of all input values.
