# sum_if

Sum non-NULL values from rows whose condition is SQL true.

**Syntax**

```text
sum_if(value, condition)
```

**Arguments**

value: numeric expression. condition: SQL truth expression. False and NULL conditions skip numeric accumulation; selected NULL values are ignored.

**Returned value**

The same numeric total and overflow behavior as sum; INTEGER 0 when no non-NULL selected value exists.

**Examples**

```sql
CREATE TABLE orders (amount INTEGER);
INSERT INTO orders VALUES (1),(NULL),(2);
```

```sql
SELECT sum_if(amount,amount > 1) FROM orders FORMAT csv;
```

```text
2
```

* [group_concat and string_agg](https://coordinatordb.com/docs/reference/functions/aggregate-functions/group-concat)

* [any_value](https://coordinatordb.com/docs/reference/functions/aggregate-functions/any-value)

* [avg](https://coordinatordb.com/docs/reference/functions/aggregate-functions/avg)

* [Aggregate combinators](https://coordinatordb.com/docs/reference/functions/aggregate-functions/combinators)

* [corr](https://coordinatordb.com/docs/reference/functions/aggregate-functions/corr)

* [count](https://coordinatordb.com/docs/reference/functions/aggregate-functions/count)

* [covar_pop](https://coordinatordb.com/docs/reference/functions/aggregate-functions/covar-pop)

* [covar_samp](https://coordinatordb.com/docs/reference/functions/aggregate-functions/covar-samp)

* [array_agg](https://coordinatordb.com/docs/reference/functions/aggregate-functions/array-agg)

* [bit_and](https://coordinatordb.com/docs/reference/functions/aggregate-functions/bit-and)

* [bit_or](https://coordinatordb.com/docs/reference/functions/aggregate-functions/bit-or)

* [bit_xor](https://coordinatordb.com/docs/reference/functions/aggregate-functions/bit-xor)

* [max](https://coordinatordb.com/docs/reference/functions/aggregate-functions/max)

* [min](https://coordinatordb.com/docs/reference/functions/aggregate-functions/min)

* [regr_avgx](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-avgx)

* [regr_avgy](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-avgy)

* [regr_count](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-count)

* [regr_intercept](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-intercept)

* [regr_r2](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-r2)

* [regr_slope](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-slope)

* [regr_sxx](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-sxx)

* [regr_sxy](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-sxy)

* [regr_syy](https://coordinatordb.com/docs/reference/functions/aggregate-functions/regr-syy)

* [stddev_pop](https://coordinatordb.com/docs/reference/functions/aggregate-functions/stddev-pop)

* [stddev_samp](https://coordinatordb.com/docs/reference/functions/aggregate-functions/stddev-samp)

* [sum](https://coordinatordb.com/docs/reference/functions/aggregate-functions/sum)

* [var_pop](https://coordinatordb.com/docs/reference/functions/aggregate-functions/var-pop)

* [var_samp](https://coordinatordb.com/docs/reference/functions/aggregate-functions/var-samp)
