# TOTAL

> TOTAL aggregate function in StackQL: the total of the non-NULL values in a column or grouping, always returned as a floating point number.

Source: https://stackql.io/language-spec/functions/aggregate/total

Returns the sum of all non `NULL` values in a column or grouping of columns.  

See also:  
[[` SELECT `]](/language-spec/select) [[` SUM `]](/language-spec/functions/aggregate/sum)

* * * 

## Syntax

```sql
SELECT TOTAL(columnExpression) FROM <multipartIdentifier>
[ GROUP BY groupByColumn ];
```

## Arguments

__*columnExpression*__  
A column or expression.

> If all the values in the *columnExpression* are `NULL` then `TOTAL` returns `0.0`.  

__*groupByColumn*__  
A column or columns used to perform summary or aggregate operations against.  The `GROUP BY` clause returns one row for each column grouping.

## Return Value(s)

Returns a floating point value representing the sum of the *columnExpression*.

* * *

## Examples

### Return the sum of a column expression over an entire resource

```sql
SELECT total(json_array_length(disks)) as total_disks
FROM google.compute.instances 
WHERE project = 'stackql-demo' 
AND zone = 'australia-southeast1-a';
```

### Return the sum of a column expression grouped by another column expression

```sql
SELECT tags, total(json_array_length(disks)) as total_disks
FROM google.compute.instances 
WHERE project = 'stackql-demo' 
AND zone = 'australia-southeast1-a'
GROUP BY json_extract(tags, '$.instanceType');
```

For more information, see [https://www.sqlite.org/lang_aggfunc.html#sumunc](https://www.sqlite.org/lang_aggfunc.html#sumunc).
