## Syntax ```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_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)) ``` ## Purpose Group function to sum together individual numerical values. Occurrences of `null` are considered 0, unless there are only `null` values. In that case the outcome is `null`. With `DISTINCT`, each unique value is summed once. ## Examples The following example retrieves the total outstanding balance across a customer base of five customers; the `null` balance of Everest BV does not influence the total: ```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 ``` The following example retrieves the total outstanding balance per customer segment; the sole Services customer has only a `null` balance, so the outcome for that segment is `null` and shown empty: ```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 ```