> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Calculates the sum. Only works for numbers.

# sum

<h2 id="sum">
  sum
</h2>

Introduced in: v1.1.0

Calculates the sum of numeric values or of intervals.

**Syntax**

```sql theme={null}
sum(num)
```

**Arguments**

* `num` — Column of numeric values or of intervals. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal*`](/reference/data-types/decimal) or [`Interval`](/reference/data-types/special-data-types/interval)

**Returned value**

Returns the sum of the values. For an `Interval` argument the result is an interval of the same unit, and an empty input gives a zero-length interval. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal*`](/reference/data-types/decimal) or [`Interval`](/reference/data-types/special-data-types/interval)

**Examples**

**Computing sum of employee salaries**

```sql title=Query theme={null}
CREATE TABLE employees
(
    id UInt32,
    name String,
    salary UInt32
)
ENGINE = Memory;

INSERT INTO employees VALUES
    (87432, 'John Smith', 45680),
    (59018, 'Jane Smith', 72350),
    (20376, 'Ivan Ivanovich', 58900),
    (71245, 'Anastasia Ivanovna', 89210);

SELECT sum(salary) FROM employees;
```

```response title=Response theme={null}
┌─sum(salary)─┐
│      266140 │
└─────────────┘
```

**Total time spent on requests**

```sql title=Query theme={null}
CREATE TABLE requests
(
    req_id UInt32,
    duration IntervalMillisecond
)
ENGINE = Memory;

INSERT INTO requests VALUES (1, 100), (2, 200), (3, 300);

SELECT sum(duration) AS total_duration, toTypeName(total_duration) FROM requests;
```

```response title=Response theme={null}
┌─total_duration─┬─toTypeName(total_duration)─┐
│            600 │ IntervalMillisecond        │
└────────────────┴────────────────────────────┘
```
