Skip to content

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