Skip to main content

ARRAY_AVG

Returns the average of the numeric items in an array. NULL elements are ignored; non-numeric values raise an error.

Syntax

ARRAY_AVG(<array>)

Return Type

Numeric (uses the smallest numeric type that can represent the result).

Examples

SELECT ARRAY_AVG([1, 2, 3, 4]) AS avg_int;

┌─────────┐
│ avg_int │
├─────────┤
2.5
└─────────┘
SELECT ARRAY_AVG([1.5, 2.5, 3.5]) AS avg_decimal;

┌──────────────┐
│ avg_decimal │
├──────────────┤
2.5000
└──────────────┘
SELECT ARRAY_AVG([10, NULL, 4]) AS avg_with_null;

┌──────────────┐
│ avg_with_null│
├──────────────┤
7.0
└──────────────┘
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today