mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-15 20:24:07 +00:00
1.1 KiB
1.1 KiB
slug | sidebar_position |
---|---|
/en/sql-reference/aggregate-functions/reference/sum | 4 |
sum
Calculates the sum. Only works for numbers.
Syntax
sum(num)
Parameters
Returned value
Example
First we create a table employees
and insert some fictional employee data into it.
Query:
CREATE TABLE employees
(
`id` UInt32,
`name` String,
`salary` UInt32
)
ENGINE = Log
INSERT INTO employees VALUES
(87432, 'John Smith', 45680),
(59018, 'Jane Smith', 72350),
(20376, 'Ivan Ivanovich', 58900),
(71245, 'Anastasia Ivanovna', 89210);
We query for the total amount of the employee salaries using the sum
function.
Query:
SELECT sum(salary) FROM employees;
Result:
┌─sum(salary)─┐
1. │ 266140 │
└─────────────┘