# Aggregations¶

In addition SQL-style aggregations (described in the section on SELECT), RAW also includes the aggregations on collections. Note that if the collection itself is nullable, then the result is null.

## CMAX¶

Find the greatest element in the collection.

Syntax:

```CMAX(<collection of number, string or temporal>)
```

For example:

```CMAX([null, 1, 2]) // 2
```

## CMIN¶

Find the smallest element in the collection.

Syntax:

```CMIN(<collection of number, string or temporal>)
```

For example:

```CMIN([1, 2]) // 1
CMIN([null, 1, 2]) // null
```

## CSUM¶

Computes the sum of all elements in the collection.

Syntax:

```CSUM(<collection of number or interval>)
```

For example:

```CSUM([1, 2]) // 3
CSUM([null, 1, 2]) // 3
```

## CAVG¶

Computes the average of all elements in the collection.

Syntax:

```CAVG(<collection of number or interval>)
```

For example:

```CAVG([1.0, 2]) // 1.5
```

## DISTINCT¶

Removes repeated elements of the collection.

Order is not maintained. The equality comparison used to determine duplicates follows the same semantics as the GROUP BY expression of the SELECT.

Syntax:

```DISTINCT(<collection>)
```

For example:

```DISTINCT([1,1,2]) // [1,2]
```

## CFIRST¶

Returns the first non null element in the collection.

Syntax:

```CFIRST(<any>)
```

For example:

```CFIRST([1, 2]) // 1
CFIRST([null, 1, 2]) // 1
```

## CLAST¶

Returns the last non null element in the collection.

Syntax:

```CLAST(<any>)
```

For example:

```CLAST([1, 2]) // 2
CLAST([1, 2, null]) // 2
```