2.2.0 (latest) 2.0.6 1.34.2 1.33.1 1.32.3 1.31.0 1.30.0 1.29.2 1.28.2 1.26.0 1.25.0 1.24.4 1.23.0 1.22.1 1.21.2 1.19.0 1.18.1 1.17.1 Reference documentation and code samples for the Cloud Datastore Client class Aggregation.

Represents Aggregation properties.

Example:

    $count = Aggregation::count();
    $count->alias('count');
    $count->limit(100);

    echo json_encode($count->getProps());

Aggregations considers non existing property name as an empty query set

## Namespace

Google \\ Cloud \\ Datastore \\ Query

## Methods

### alias

Set the aggregation alias.

Example:

    $count = Aggregation->count();
    $count->alias('total');

    echo $count->props()['count']['alias'];

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `alias` | `string` The alias for aggregation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-datastore/latest/Query.Aggregation` |   |

### getProps

Get the array representation for the aggregation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### static::count

Creates count aggregation properties.

Example:

    $count = Aggregation::count();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-datastore/latest/Query.Aggregation` |   |

### static::sum

Creates sum aggregation properties.

Example:

    $sum = Aggregate::sum('property_to_aggregate_upon');

Result of SUM aggregation can be a integer or a float.
Sum of integers which exceed maxinum integer value returns a float.
Sum of numbers exceeding max float value returns `INF`.
Sum of data which contains `NaN` returns `NaN`.
Non numeric values are ignored.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `property` | `string` The relative path of the field to aggregate upon. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-datastore/latest/Query.Aggregation` |   |

### static::avg

Creates average aggregation properties.

Example:

    $avg = Aggregate::avg('property_to_aggregate_upon');

Result of AVG aggregation can be a float or a null.
Average of empty valid data set return `null`.
Average of numbers exceeding max float value returns `INF`.
Average of data which contains `NaN` returns `NaN`.
Non numeric values are ignored.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `property` | `string` The relative path of the field to aggregate upon. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-datastore/latest/Query.Aggregation` |   |