# Aggregate queries

Aggregate queries in GraphQL are useful for summarizing data in various ways. They help in performing operations such as counting the number of records, summing up numerical fields, and grouping data based on specific fields.

Add `_aggregate` with any asset type to perform aggregate queries. `_count`, `_sum` and `_groupby` are currently supported.

#### <mark style="color:blue;">Count Query</mark>

The `count` query allows you to count the number of records that match a specific condition.

```graphql
{
    Invoice_aggregate {
        _count
    }
}
```

Example:

```graphql
{
    Invoice_aggregate (status: "updated") {
        _count
    }
}
```

In this example, the query counts the invoices a 'updated' status.

***

#### <mark style="color:blue;">Sum Query</mark>

The `sum` query allows you to sum the values of a specific numerical field across all records that match a given condition.

```graphql
{
    Invoice_aggregate {
        _sum {
            amount
        }
    }
}
```

Example:

```graphql
query {
  Invoice_aggregate(where: { status: "updated" }) {
          _sum {
              amount
        }
      }
}
```

In this example, the query sums up the amount of all invoices that have a 'updated' status.

***

#### <mark style="color:blue;">Group By Query</mark>

The `groupBy` query allows you to group records by a specific field and perform aggregate functions like count or sum within each group.

```graphql
{
    Invoice_aggregate {
        _count
        _groupby{
            invoiceType
        }
    }
}
```

Example:

```graphql
{
    Invoice_aggregate (status: "updated") {
        _count
        _groupby{
            invoiceType
        }
    }
}
```

This query groups invoices by their type and provides the count of the invoices with 'updated' status.
