メインコンテンツまでスキップ
メインコンテンツまでスキップ

sum

合計を計算します。数値にのみ機能します。

構文

sum(num)

パラメータ

返される値

まず、テーブル employees を作成し、いくつかの架空の従業員データを挿入します。

クエリ:

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);

sum 関数を使用して、従業員の給与の合計をクエリします。

クエリ:

SELECT sum(salary) FROM employees;

結果:

   ┌─sum(salary)─┐
1. │      266140 │
   └─────────────┘