Skip to main content Skip to complementary content

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)
}

Related functions

  • arrayAvg - Calculates the average of values in an array
  • sum - Calculates the sum in an iterative context

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!