---
title: "Sum \u96C6\u8A08 Function (*.fnc)"
description: "\u500B\u3005\u306E\u6570\u5024\u3092\u5408\u8A08\u3059\u308B\u30B0\u30EB\u30FC\u30D7\u95A2\u6570\u3067\u3059\u3002"
language: ja
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/ja/docs/invantive-universalsql/grammar/aggregate-functions/sum-aggregate-function
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/aggregate-functions/sum-aggregate-function
updated: 2026-12-04T12:49:34Z
license: https://documentation.invantive.eu/ja/
---

## 構文
```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    sumAggregateFunction_start((START))
    sumAggregateFunction_start --> sumAggregateFunction_0_0[SUM]:::quoted
    sumAggregateFunction_0_0 --> sumAggregateFunction_0_1["("]:::quoted
    sumAggregateFunction_0_1 --> sumAggregateFunction_0_2[DISTINCT]:::quoted
    sumAggregateFunction_0_1 --> sumAggregateFunction_0_2a[ALL]:::quoted
    sumAggregateFunction_0_2a --> sumAggregateFunction_0_3
    sumAggregateFunction_0_2 --> sumAggregateFunction_0_3[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    sumAggregateFunction_0_3 --> sumAggregateFunction_0_4[")"]:::quoted
    sumAggregateFunction_0_4 --> sumAggregateFunction_end((END))
```

## 目的
個々の数値を合計するグループ関数です。 `null`の出現は0とみなされますが、`null`の値しかない場合は除きます。 その場合、結果は`null`になります。 `DISTINCT`を指定すると、各一意の値は一度だけ合計されます。 `ALL`(既定値)を指定すると、各値は出現した回数分だけ計上されます。`ALL`はリリース28.0から使用できます。

## 例
次の例では、5社の顧客ベース全体の未払残高合計を取得します。Everest BVの`null`残高は合計に影響しません:
```sql
select sum(cus.balance)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus

-------------------
22500
```
次の例では、顧客セグメントごとの未払残高合計を取得します。Services顧客は1社のみで`null`残高しかないため、そのセグメントの結果は`null`となり、空で表示されます:
```sql
select cus.segment
,      sum(cus.balance)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus
group
by     cus.segment
order
by     cus.segment

-------------------
Manufacturing    12500
Services
Wholesale        10000
```

