# sum_simple_state

`sum_simple_state` calculates a partial sum and returns a directly readable scalar wrapped as SimpleAggregateFunction. Ordinary `sum` can combine those partial values again.

Unlike a full AggregateFunction state, the scalar does not need `_merge` or `finalize_aggregation` before it can be read.

## Prepare two batches

```sql
CREATE TABLE readings(batch UInt8, value Int64);
INSERT INTO readings VALUES (1, 10), (1, 20), (2, 90);
CREATE TABLE partials(batch UInt8, result SimpleAggregateFunction(sum, Int64));
INSERT INTO partials
SELECT batch, sum_simple_state(value)
FROM readings
GROUP BY batch;
```

## Read partial results

```sql
SELECT batch, result
FROM partials
ORDER BY batch
FORMAT csv;
```

```text
1,30
2,90
```

## Combine the scalars

```sql
SELECT sum(result)
FROM partials
FORMAT csv;
```

```text
120
```

The table does not combine rows automatically when values are inserted. Use an explicit aggregate query. See [SimpleAggregateFunction](https://coordinatordb.com/docs/reference/data-types/simpleaggregatefunction) for the supported inner types and functions.
