avg
Calculates the average of numeric values in an iterative context.
The avg function returns the average value of a numeric field across multiple rows in an iterative context, such as with a GROUP BY clause or in a FROM-SELECT query.
To calculate the average of values in an array or collection, use the arrayAvg function instead.
Arguments
Expression returning a numeric value.
Examples
Calculate the average rating across all customers:
FROM customer
SELECT avg(rating)Calculate the average quantity per order:
FROM order UNNEST items
GROUP BY order_id
SELECT {
order_id,
avg_quantity = avg(quantity)
}