sum
Returns the sum of numeric values in an iterative context.
The sum function returns the sum of numeric values across multiple rows in an iterative context, such as with a GROUP BY clause or in a FROM-SELECT query.
To calculate the sum of values in an array or collection, use the arraySum function instead.
Arguments
Expression returning a numeric value.
Examples
Calculate the total price across all orders:
FROM order
SELECT sum(price)Calculate the total quantity per order:
FROM order UNNEST items
GROUP BY order_id
SELECT {
order_id,
total_quantity = sum(quantity)
}